Skip to content

Instantly share code, notes, and snippets.

@hprobotic
Created September 11, 2019 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hprobotic/0031aad46d0515064a6d12a746101553 to your computer and use it in GitHub Desktop.
Save hprobotic/0031aad46d0515064a6d12a746101553 to your computer and use it in GitHub Desktop.
Stripe payment
def create_stripe_payment(recipient_type, payment_method, scheduled_transaction, current_user, total_charge):
connected_stripe_account_id = get_stripe_account_id(
recipient_type,
payment_method.brand,
scheduled_transaction.source_currency)
paymentIntent = None
# Old method => Need to do migrate
dest_charge = None
try:
pay_source = stripe.Source.create(
customer=current_user.stripe_customer,
original_source=payment_method.stripe_card,
stripe_account=connected_stripe_account_id)
dest_charge = stripe.Charge.create(
amount=total_charge,
currency=scheduled_transaction.source_currency,
source=pay_source.id,
stripe_account=connected_stripe_account_id,
description=scheduled_transaction.description)
return dest_charge
# New
try:
paymentIntent = stripe.PaymentIntent.create(
amount=total_charge,
currency=scheduled_transaction.source_currency,
payment_method_types=['card'],
customer=current_user.stripe_customer,
payment_method=payment_method.intent_payment_method,
confirm=True,
description=scheduled_transaction.description,
on_behalf_of=connected_stripe_account_id,
transfer_data={'destination': connected_stripe_account_id},
return_url='{}/dashboard/payments/'.format(CLIENT_URL)
)
return paymentIntent
except stripe.error.CardError as e:
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment