Skip to content

Instantly share code, notes, and snippets.

View miodeqqq's full-sized avatar
👨‍💻
Coding...

Maciej Januszewski miodeqqq

👨‍💻
Coding...
View GitHub Profile
@miodeqqq
miodeqqq / stripe_and_django.py
Created September 2, 2020 13:15
Django & Stripe
# managers.py
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import ugettext_lazy as _
class UserManager(BaseUserManager):
"""
Custom User manager to be used with default auth User model.
"""
@miodeqqq
miodeqqq / refund_money_to_customer.py
Created September 2, 2020 13:08
Django & Stripe - refund_money_to_customer.py
stripe.PaymentIntent.cancel(payment_intent.id)
@miodeqqq
miodeqqq / decrease_connect_account_balance.py
Created September 2, 2020 13:08
Django & Stripe - decrease_connect_account_balance.py
stripe.Charge.create(
amount=amount,
currency="pln",
source=user2.stripe_id,
description=description
)
@miodeqqq
miodeqqq / check_connect_account_balance.py
Created September 2, 2020 13:07
Django & Stripe - check_connect_account_balance.py
stripe.Balance.retrieve(stripe_account=user2.stripe_id)
@miodeqqq
miodeqqq / charge_customer_card_and_confirm.py
Created September 2, 2020 13:07
Django & Stripe - charge_customer_card_and_confirm.py
stripe.PaymentIntent.capture(
payment_intent.id, amount_to_capture=amount
)
@miodeqqq
miodeqqq / charge_customer_card.py
Created September 2, 2020 13:06
Django & Stripe - charge_customer_card.py
payment_method = stripe.Customer.retrieve(user1.stripe_id).default_source
payment_intent = stripe.PaymentIntent.create(
amount=amount,
currency="pln",
payment_method_types=["card"],
capture_method="manual",
customer=user1.stripe_id, # customer
payment_method=payment_method,
application_fee_amount=application_fee_amount,
@miodeqqq
miodeqqq / add_customer_card.py
Created September 2, 2020 13:05
Django & Stripe - add_customer_card.py
new_card_source = stripe.Customer.create_source(user1.stripe_id, source=token)
stripe.SetupIntent.create(
payment_method_types=["card"],
customer=user1.stripe_id,
description="some description",
payment_method=new_card_source.id,
)
@miodeqqq
miodeqqq / attach_identity_document.py
Last active April 23, 2021 15:25
Django & Stripe - attach_identity_document.py
passport_front = stripe.File.create(
purpose="identity_document",
file=_file, # ContentFile object
stripe_account=user2.stripe_id,
)
individual = {
"verification": {
"document": {"front": passport_front.get("id"),},
"additional_document": {"front": passport_front.get("id"),},
@miodeqqq
miodeqqq / accept_stripe_policy.py
Created September 2, 2020 13:04
Django & Stripe - accept_stripe_policy.py
tos_acceptance = {"date": int(time.time()), "ip": user_ip},
stripe.Account.modify(user2.stripe_id, tos_acceptance=tos_acceptance)
@miodeqqq
miodeqqq / create_connect_account.py
Created September 2, 2020 13:03
Django & Stripe - create_connect_account.py
mcc_code, url = "1520", "https://www.softserveinc.com/"
response_ca = stripe.Account.create(
type="custom",
country="PL",
email=user2.email,
default_currency="pln",
business_type="individual",
settings={"payouts": {"schedule": {"interval": "manual", }}},
requested_capabilities=["card_payments", "transfers", ],