Skip to content

Instantly share code, notes, and snippets.

@hprobotic
Created September 16, 2019 18:53
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/25f0e769f88d51b5498e43d2dbddb336 to your computer and use it in GitHub Desktop.
Save hprobotic/25f0e769f88d51b5498e43d2dbddb336 to your computer and use it in GitHub Desktop.
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