Created
September 16, 2019 18:53
-
-
Save hprobotic/25f0e769f88d51b5498e43d2dbddb336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
# Use both stripe_card or intent_payment_method is workable to charge | |
stripe_payment_method = payment_method.intent_payment_method or payment_method.stripe_card | |
idempotency_key = random_string_generator(20) | |
token = stripe.Token.create( | |
customer=current_user.stripe_customer, | |
stripe_account=connected_stripe_account_id | |
) | |
customer = stripe.Customer.create( | |
description='Shared Customer: {} {}'.format(current_user.first_name, current_user.last_name), | |
source=token.id, | |
stripe_account=connected_stripe_account_id | |
) | |
payment_method = stripe.PaymentMethod.create( | |
customer=current_user.stripe_customer, | |
payment_method=stripe_payment_method, | |
stripe_account=connected_stripe_account_id, | |
) | |
paymentIntent = stripe.PaymentIntent.create( | |
amount=total_charge, | |
currency=scheduled_transaction.source_currency, | |
payment_method_types=['card'], | |
payment_method=payment_method.id, | |
confirm=True, | |
customer=customer.id, | |
description=scheduled_transaction.description, | |
stripe_account=connected_stripe_account_id, | |
idempotency_key=idempotency_key | |
) | |
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