#alx8523
1 messages · Page 1 of 1 (latest)
code in question:
stripe_account_id = "acct_1Nd2QzIvcngBFA23"
destination_account = "acct_1Nd2TxI6FBH5XxxO"
# Creates a Customer in destination account
customer = stripe.Customer.create(
email=user.email,
name=user.first_name + " " + user.last_name,
stripe_account=destination_account,
)
pm = stripe.PaymentMethod.attach(
user.userprofile.stripe_payment_method_id,
customer="cus_OPsJtwwjxMWUWV",
stripe_account=stripe_account_id,
)
# Create a PaymentIntent
payment_intent = stripe.PaymentIntent.create(
amount=int(Decimal(str(offer.price)) * Decimal("1.2") * Decimal("100")),
currency="ron",
customer="cus_OPsJtwwjxMWUWV",
payment_method=pm,
confirm=True,
application_fee_amount=application_fee_amount,
transfer_data={
"destination": destination_account,
},
stripe_account=stripe_account_id,
)
You are using both stripe_account and destination_account
Remove that stripe_account.
Thank you, that error seems to have gone away but now I get "No such PaymentMethod".
i create the pm in accounts django app and save them all in the database then i retrieve them when i need them for the job app. Here's how I create the pm.
user = request.user
payment_method_id = request.data.get("paymentMethodId")
stripe_customer_id = user.userprofile.stripe_customer_id
stripe_account_id = user.userprofile.stripe_account_id
try:
stripe.Customer.retrieve(stripe_customer_id, stripe_account=stripe_account_id)
except InvalidRequestError:
customer = stripe.Customer.create(
email=user.email,
description=f"Customer for user {user.username}",
stripe_account=stripe_account_id,
)
stripe_customer_id = customer.id
user.userprofile.stripe_customer_id = stripe_customer_id
user.userprofile.save()
try:
stripe.PaymentMethod.attach(
payment_method_id,
customer=stripe_customer_id,
stripe_account=stripe_account_id, # Make sure this is the ID of the connected account that owns the Payment Method
)
except InvalidRequestError as e:
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
user.userprofile.stripe_payment_method_id = payment_method_id
user.userprofile.save()
serializer = UserSerializer(user, many=False)
return Response(serializer.data)
Sorry it's a lot of code and hard to follow. I suggest finding your error request on your Dashboard log first
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sorry about that. Yes, it is a simple 'resource_missing - payment_method'
What is the request id? req_xxx
I think I found the problem. It shouldn't have destination just stripe_account here
```payment_intent = stripe.PaymentIntent.create(
amount=int(Decimal(str(offer.price)) * Decimal("1.2") * Decimal("100")),
currency="ron",
customer="cus_OPsJtwwjxMWUWV",
payment_method=pm,
confirm=True,
application_fee_amount=application_fee_amount,
transfer_data={
"destination": destination_account,
},
stripe_account=stripe_account_id,
)```
Am I right?
req: req_kuBvcXShMcOoRM
To be more clear: I commented out transfer_data and it seems to maybe have worked