#malphine2

1 messages ยท Page 1 of 1 (latest)

subtle tartanBOT
obsidian abyss
#

This card allows setting up a card successfully with Setup Intent and simulate failure during payment

lavish elk
#

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

obsidian abyss
#

No, this test card will fail when trying to place a hold.

lavish elk
#

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']
obsidian abyss
#

Is there any problem you're facing?

lavish elk
#

im just confused, because i thought that this card

#

would not allow me to create a hold

#

but it did

obsidian abyss
#

Can you share the Payment Intent ID (pi_xxx) that the holds was successful with this test card?

lavish elk
#

pi_3N7rWzH8GIP1lNIu0keovevQ

obsidian abyss
lavish elk
#

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

obsidian abyss
#

Doesn't the placing on hold work for you? The flow should be:

  1. 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
  2. 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
  3. 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

lavish elk
#

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
    )


obsidian abyss
#

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

lavish elk
#

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

obsidian abyss
#

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

lavish elk
#

where is the pm_xxx in the setup intent object? right now, in the link you provided i see

"payment_method": "src_1MX6Yb285d61s2cIuxZ2cFHg",

obsidian abyss
lavish elk
#

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 ๐Ÿ˜ญ

obsidian abyss
#

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

lavish elk
#

Alright, thanks a lot

#

you deserve a 200k salary your a beast

obsidian abyss
#

No problem! Happy to help ๐Ÿ˜„

subtle tartanBOT
lavish elk
# obsidian abyss 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

timber girder
#

Hi @lavish elk I'm taking over

lavish elk
#

Hello ๐Ÿ‘‹

timber girder
#

This is a newly created setup mode checkout session and it's not yet completed, am I right?

lavish elk
#

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

timber girder
#

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.

Learn about the status and lifecycle of PaymentIntents and SetupIntents.

lavish elk
#

'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 ?

timber girder
#

Before we go deep into that, can you tell me what you want to achieve with Stripe APIs?

lavish elk
#

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

timber girder
lavish elk
#

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?

timber girder
#

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?

lavish elk
#

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

timber girder
lavish elk
#

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

timber girder
#

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.

lavish elk
#

when they confirm their payment, it wont charge them right? it would just create a hold that lasts 7 days corect?

timber girder
#

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.

lavish elk
#

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 ?

timber girder
lavish elk
#

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

timber girder
#

Can you share with me the PaymentIntent ID?

lavish elk
#

card_1N7oo9H8GIP1lNIuQPfVjKXR

timber girder
#

The PaymentIntent ID starts with pi_, you can find it from the response of stripe.PaymentIntent.create

lavish elk
#

pi_3N7tJ0H8GIP1lNIu11H96STO

timber girder
#

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.

lavish elk
#

YOUR A GENIUS BRO

#

NO WONDER UR A MODERATOR!

#

THANK YOU SO MUCH ๐Ÿ˜ƒ

timber girder
#

Welcome!

lavish elk