#malphine2
1 messages ยท Page 1 of 1 (latest)
This card allows setting up a card successfully with Setup Intent and simulate failure during payment
so it allows for holds to be created with this card?
are there cards on the test website taht would fail if you try to put a hold
No, this test card will fail when trying to place a hold.
You can use any of the test cards here for declining the payment: https://stripe.com/docs/testing#declined-payments
i made hold using this code
payment_intent = stripe.PaymentIntent.create(
amount=amount,
currency='cad',
payment_method_types=['card'],
capture_method='manual',
customer= customer
)
return payment_intent['id']
If you want to simulate payment failures, you may use the test cards here instead: https://stripe.com/docs/testing#declined-payments
Is there any problem you're facing?
im just confused, because i thought that this card
would not allow me to create a hold
but it did
Can you share the Payment Intent ID (pi_xxx) that the holds was successful with this test card?
pi_3N7rWzH8GIP1lNIu0keovevQ
Where did you see the successful payment? In https://dashboard.stripe.com/test/payments/pi_3N7rWzH8GIP1lNIu0keovevQ, the payment is still in requires_payment_method status that no payment method is collected on this payment intent
I'd recommend following this guide to check how to collect a payment method with Payment Element: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
oh i see, then i have a different problem
basically, is there a feature in stripe where its simliar to uber eats where
you buy food from a resturant , and then you only get cahraged after the deilvery order sucsusfully dropped off the food. However, service wont go through if your card got declined at the very beginning. Like in uber eats, it wont let you make an order if your card gets declined
how can i make that check ? Like make sure their card doesn't get declined if i were to charge them
Doesn't the placing on hold work for you? The flow should be:
- Use Setup Intent to collect and save the payment method details for future usage (no payment at this time) like saving a payment method into Customer's account: https://stripe.com/docs/payments/save-and-reuse
- When the customer is about to place the order, you will then place a hold on the amount with the saved payment method in Step 1: https://stripe.com/docs/payments/place-a-hold-on-a-payment-method
- Once the order is delivered, then capture the Payment Intent in Step 2
In your current code, it didn't set any payment_method in the request
oh
would it be
payment_intent = stripe.PaymentIntent.create(
amount=amount,
currency='cad',
payment_method_types=['card'],
capture_method='manual',
customer= customer
payment_method= card_id
)
Yes, but your current card information collection with /v1/tokens is legacy and no longer recommend. You should use Setup Intent with the guide in Step 1 to collect payment method (pm_xxx) instead
I assume
session = stripe.checkout.Session.create(
payment_method_types=['card'],
mode='setup',
customer='{{CUSTOMER_ID}}',
)
session returns a setup intent like
stripe.checkout.Session.retrieve(
"cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k",
)
'seti_1EzVO3HssDVaQm2PJjXHmLlM'
how would i use seti_1EzVO3HssDVaQm2PJjXHmLlM to create my payment intent
or would it not let me create a setup intent in the first place as my card would get declined
stripe.checkout.Session is to use Checkout Session, Stripe hosted payment page to collect the payment. After the payment method is collected successfully, the payment_method will be present in SetupIntent object (https://stripe.com/docs/api/setup_intents/object#setup_intent_object-payment_method). You can then use this Payment Method (pm_xxx) to set in the payment_method on the Payment Intent
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
where is the pm_xxx in the setup intent object? right now, in the link you provided i see
"payment_method": "src_1MX6Yb285d61s2cIuxZ2cFHg",
In https://dashboard.stripe.com/test/setup_intents/seti_1EzVO3HssDVaQm2PJjXHmLlM, the payment method is in pm_xxx, but it was created very long time ago
Could you share where you retrieve src_1MX6Yb285d61s2cIuxZ2cFHg from? It wasn't created from Setup Intent: https://dashboard.stripe.com/test/logs/req_Y2xkzxnJkVuUjC
i got it from the img provided in the link, i have not created any objects yet
ill create a setup intent object now and see what format the payment method is
sorry for being so difficult ๐ญ
Ah I see! I'd recommend following the steps and guides I provided earlier. You should be able to get payment method ID (pm_xxx) from Setup Intent, which can further be used in Payment Intent
No problem! Happy to help ๐
Sorry im being dumb ๐ญ
session = stripe.checkout.Session.create(
payment_method_types=['card'],
mode='setup',
customer=customer,
success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url='https://example.com/cancel',
)
complete = stripe.checkout.Session.retrieve(session['id'],)
intent = stripe.SetupIntent.retrieve(complete['setup_intent'])
print(intent)
this prints out
info..
"payment_method": null,
"payment_method_types": [
"card"
],,
"status": "requires_payment_method",
why is it null here and that status requires_payment_method
Hi @lavish elk I'm taking over
Hello ๐
This is a newly created setup mode checkout session and it's not yet completed, am I right?
yeah basically, in our above conversation, i would like to create a payment method by making a setup intent obejct. Just a bit confused on how to exactly retrive that from the setup intent
OK. I'd suggest to read about the setup intent lifecycle here: https://stripe.com/docs/payments/intents?intent=setup so requires_payment_method is the initial state of the setup intent, once your customer has completed the checkout session through the checkout page, it would eventual transit to succeeded state if the setup is confirmed successfully, and at that time you are able to retrieve a payment_method from the checkout session.
'When the SetupIntent is created, it has a status of requires_payment_method1 until a payment method is attached.'
how exactly do i do that ?
Before we go deep into that, can you tell me what you want to achieve with Stripe APIs?
Basically
2 Steps i need to do
create a hold on a customer's account using thier payment (here i also make sure that they can affod the payment on the day of the transaction)
capture the funds on the day of the transaction
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#auth-and-capture looks like you are looking for this, not setupIntent.
here,
amount=amount,
currency='cad',
payment_method_types=['card'],
capture_method='manual',
customer= customer
payment_method= card_id
)
``` i was creating a hold, but river suggested i use a setup intent to get the payment mehtod
oo
ok ill try this
so i should not be creating a setup intent object?
and like what about the hold?
Stripe can only hold the fund up to 7 days, if you need to capture it after 7 days, then you need to use setup intent to collect the payment method and charge the customer later.
Do you have a chance to go through the doc that I sent earlier and test the code in your integration?
Sorry, yeah so heres what i have,
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[
{
"price_data": {
"currency": "cad",
"product_data": {"name": "T-shirt"},
"unit_amount": amount,
},
"quantity": 1,
},
],
mode='payment',
payment_intent_data={"capture_method": "manual"},
customer=customer,
success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url='https://example.com/cancel',
)
complete = stripe.checkout.Session.retrieve(session['id'],)
print(complete)
does this mean i have created a hold ? or
Looks good, did you try redirect to the checkout page and complete the checkout session? https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#redirect-customers
the checkout page u just mean the sucsess_url right? and what do you mean by completing the checkout sesison
sorry i think we are on different pages, im kinda confsued to what this checkout session does for me as i read thorugh it
The checkout session has an field called "URL", you should redirect your customer to this URL to open the checkout page where they can input the credit details and confirm the payment.
when they confirm their payment, it wont charge them right? it would just create a hold that lasts 7 days corect?
Yes you are right.
If you don't capture the payment within 7 days, Stripe will automatically release the funds and return to your customer.
Okay, but for the checkout session page, i dont want them to enter their card details again, as i already have all that saved in their customer account. How could i use the customer obeject to confrim the payment for them ?
If you have already collected the payment method, you don't need to use checkout session. You can simply create a PaymentIntent to charge your customer with the saved payment method https://stripe.com/docs/payments/save-and-reuse?platform=web#charge-saved-payment-method
sorry for all of this i am a noob in coding
will try this
def createAHold(amount, customer):
method = stripe.PaymentMethod.list(customer=customer, type="card")
payment_intent = stripe.PaymentIntent.create(
amount=amount,
currency='cad',
payment_method_types=['card'],
capture_method='manual',
customer= customer ,
payment_method= method['data'][0]['id']
)
return payment_intent['id']
ok so with this code
i sucsessfully created a hold
however
the card that is assoicated with the customer is this card
but it still went through
Can you share with me the PaymentIntent ID?
card_1N7oo9H8GIP1lNIuQPfVjKXR
The PaymentIntent ID starts with pi_, you can find it from the response of stripe.PaymentIntent.create
pi_3N7tJ0H8GIP1lNIu11H96STO
The paymentIntent's status is still requires_confirmation, you can set both off_session:true and confirm:true when creating a paymentIntent to confirm it immediately. Refer to the example code in the doc that I sent to you earlier.
Welcome!
By the way, is there a 7 day holding period like there is with a checkout session