#Parth R. Jangid (Pseudo Bugs)
1 messages · Page 1 of 1 (latest)
You shouldn't really pass a payment method to a setup intent. You should use the setup intent's client secret to collect the payment method details. If a customer was passed to the setup intent on creation or update, it will automatically be attached to that customer. Follow this flow: https://stripe.com/docs/payments/save-and-reuse?platform=ios&ui=payment-sheet
Thanks for the reference but I didn't understand from it that well, I am confused.
I need some clarification on this. My current code attaches a payment method to my customer okay. I am not sending anything else other than my payment Method ID to my server. So is this okay to do so? Earlier I have sending card details directly and Rebeus not to do so until I am PCI complaint which I amm not.
2nd Query is that why do we use set up intent?
3rd what did you mean by this: You should use the setup intent's client secret to collect the payment method details.?
Like I am passing the customer while I create the set up intent okay and then I am returning the client secret to my iOS App then how do I do what you are trying to say?
So is this okay to do so?
How are you currently creating the PM? The PM should be created when you submit payment details on the setupintent, so that's not recommended.
2nd Query is that why do we use set up intent?
SetupIntents are used to create payment methods so that they are set up for future use (reduces liklihood of decline or needing 3ds auth later on)
Like I am passing the customer while I create the set up intent okay and then I am returning the client secret to my iOS App then how do I do what you are trying to say?
That would be this step in the guide I sent you: https://stripe.com/docs/payments/save-and-reuse?platform=ios&ui=payment-sheet#collect-payment-details
I understood the answer to 2nd.
For the 1st question: I have a Checkout button on clicking that I am fetching the Setup Intent's client secret and then creating a Payment Method like this:
STPAPIClient.shared.createPaymentMethod(with: paymentMethodParams)
Then I was sending this to another backend endpoint to confirm the Setup Intent but it didn't work.
Yeah you shouldn't do that
Follow the guide I sent
If you submit payment method details properly on the setupintent a payment method will be automatically created for you
Read over that guide
I tried understanding that Collect payment details step but I want to ask you that it is using Stripe's built in payment Sheet. It is creating an object and then passing it to the PaymentButton button but I am not using Payment Sheet in my application.
Nah not my own form instead using this: STPPaymentCardTextField
So like I have a checkbox so if the user selects that then before processing the payment I want to save that card for that user and then proceed ahead with the payment.
Oh ok. Just curious, why not use the payment sheet?
Like it's someone else's project so I have to stick to what they say.
So like what I am trying to do is that possible? Is there any way to do this?
Ok I think it's possible
So our Accept a payment guide has a tab where we use the STPPaymentCardTextField: https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=custom#ios-submit-payment
In that guide, you'll notice that we create a PaymentIntent and pass its client secret to collect payment method details and submit payment
You should be able to just substitute out that PaymentIntent with a SetupIntent and use the SetupIntent's client secret to collect payment details and set it up for future use
Okay I will look into it but in the meanwhile please don't close this thead
We close threads after some inactivity because the open thread list gets unmaintainable
If you come back later and thread is closed, just message in main channel and we'll open up a new one
Oh okay
Hi,
Can you point me to a reference where I can see if any method like STPSetupIntentParams exists
Hi 👋
Our iOS SDK documentation is here: https://stripe.dev/stripe-ios/documentation/stripe/
And the actual SDK is here: https://github.com/stripe/stripe-ios
Oh okay I look into that too.
So @lean blaze , is STPAPIClient.shared.confirmSetupIntent and STPPaymentHandler.shared().confirmSetupIntent the same thing?
Can you link to the docs where you are seeing these objects?
@lean blaze I believe it worked but I need a confirmation from your side whether I am not violating any policies/regulations. Please bear with me I will post some small snippet of code.
yes
https://onmyway133.com/posts/how-to-use-payment-intent-and-setup-intents-with-stripe-in-ios/
I am using this as reference
Issue #356
StripeHandler.swift
From Stripe 16.0.0 https://github.com/stripe/stripe-ios/blob/master/CHANGELOG.md#1600-2019-07-18
Migrates STPPaymentCardTextField.cardParams property type from STPCardParams to STPPaymentMethodCardParams
final class StripeHandler { func createPaymentMethod( textField: STPPaymentCardTextField, completion: @escapin...
I cannot give any legal advice, I can only discuss integrations with Stripe APIs
So currently my code added a card to my user's Stripe account.
After fetching the client secret from server:
if let card = paymentMethodsParams?.card {
if let cardNumber = card.number,
let expMonth = card.expMonth,
let expYear = card.expYear,
let cvc = card.cvc {
let cardParams=STPPaymentMethodCardParams()
cardParams.number = cardNumber
cardParams.expMonth = expMonth
cardParams.expYear = expYear
cardParams.cvc = cvc
let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: nil, metadata: nil)
let setupIntentParams = STPSetupIntentConfirmParams(clientSecret: clientSecret)
setupIntentParams.paymentMethodParams = paymentMethodParams
STPAPIClient.shared.confirmSetupIntent(with: setupIntentParams) { setupIntentResult, error in
if let error = error {
print("Error confirming SetupIntent: \(error)")
return
}
print("setupIntentResult^^^^: \(setupIntentResult)") }```
So this code added the card to the user's account but I just want to confirm that this code has nothing to do with being PCI complaint right? Not legal advice but just is this correct way?
Got it.
So this code does work. Like it adds the payment method to the account but the log in my Stripe Dashboard:
POST /v1/setup_intents has many fields set to null:
"payment_method_options": {
"card": {
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"status": "requires_payment_method",```
Why is that so?
Do you have the request ID?
req_CfUH6ClI078Wol this correct?
Okay, you only passed the customer and nothing else. So all the other fields are empty or null
Oh and I don't know why was my card details not passed because my code is like this:
let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: nil, metadata: nil)
let setupIntentParams = STPSetupIntentConfirmParams(clientSecret: clientSecret)
setupIntentParams.paymentMethodParams = paymentMethodParams
STPAPIClient.shared.confirmSetupIntent(with: setupIntentParams) { setupIntentResult, error in
if let error = error {
print("Error confirming SetupIntent:\(error)")
return
}
print("setupIntentResult^^^^: \(setupIntentResult)")
}
setupIntentParams.paymentMethodParams = paymentMethodParams
Isn't this step correct?
Are you sure there are card details in the cardParams object?
I will print it and share the exact response, that will help
Printing the cardParams: <StripePayments.STPPaymentMethodCardParams: 0x600003f4fa70; last4 = 4242; expMonth = 2; expYear = 45; cvc = <redacted>; token = >
2023-06-16 10:13:21.729273-0700 sofiit[6882:14500074] LOG ANALYTICS: ["publishable_key": "some_key_I_have_hidden", "app_version": "1.0", "install": "S", "apple_pay_enabled": 1, "additional_info": [], "company_name": "sofiit", "os_version": "16.4", "bindings_version": "23.9.0", "ocr_type": "none", "pay_var": "legacy", "product_usage": ["STPPaymentCardTextField"], "device_type": "arm64", "source_type": "card", "event": "stripeios.setup_intent_confirmation", "analytics_ua": "analytics.stripeios-1.0", "app_name": "sofiit"]
The weird thing is that the card is being added the Stripe Account but the response has no details of card.
My events looks like this:
SetupIntent seti_1NJgD7BilogIeZ8xCWqgbBnK has succeeded - 6/16/23, 10:13:22 AM
A card payment method ending in 4242 was attached to customer cus_O2cK7KonnxAZ0g
6/16/23 - 10:13:22 AM
A new SetupIntent seti_1NJgD7BilogIeZ8xCWqgbBnK was created - 6/16/23, 10:13:21 AM
And this request did pass all the required parameters. You can see that here: https://dashboard.stripe.com/test/logs/req_7KyRsbH1xpcOqk
Got it sir. Thank you so much. But this is the correct way right to add payment method right? Now I understood that I the paymentMethodId is what I should extract from the setupIntentResult
One last question the official docs say that:
Instead of passing this to STPAPIClient.confirmSetupIntent(...) directly, we recommend using STPPaymentHandler to handle any additional steps for you.
I understood that sometime there will be authentication and then user might be navigated to browser if var useStripeSDK is false, So like I can set the return URL. So like how should one handle authentication?
Good question, finding our docs on handling 3DS now...
Can you link to the doc that you are using now by the way? Found the doc you are looking at: https://stripe.dev/stripe-ios/stripe/documentation/stripe/stpsetupintentconfirmparams
So here is the doc on 3DS:
https://stripe.com/docs/payments/3d-secure#when-to-use-3d-secure
If you are using a webview then you can provide your return URL while confirming the SetupIntent which we have a param for in that STPSetupIntentConfirmParams object:
https://stripe.dev/stripe-ios/stripe/documentation/stripe/stpsetupintentconfirmparams/returnurl
Damn this is too much.
I will look into this. Thank you so much for the reference.
Also, I have this query in mind:
I am using this STPAPIClient.shared.confirmSetupIntent right now okay. And the https://stripe.dev/stripe-ios/stripe/documentation/stripe/stpsetupintentconfirmparams docs says that I should use STPPaymentHandler and the 3DS docs also seem to be using STPPaymentHandler.
So then I will refactor code but then STPPaymentHandler has a method confirmSetupIntent which needs authenticationContext: STPAuthenticationContext so where do I get this from?
Also using this approach of creating a setup intent and creating a new payment method on iOS side and then confirming is allowing me to attach the card twice. A card with same details was already existing and then I did this process one more time and again it added the payment method. The id is different but the finger print is the same. So is it my duty to keep track of fingerprints and only process if it does not already exists?
Good question, I am trying to find docs that show this in more detail. I can see STPAuthenticationContext in our examples on GitHub https://github.com/stripe/stripe-ios/blob/ec29d082/Example/Non-Card Payment Examples/Non-Card Payment Examples/AffirmExampleViewController.swift#L111
Yes, Stripe doesn't check if you already have this card saved, it will just attach the card. If you want to prevent duplicates, checking the fingerprint against the fingerprint of cards already saved to the user is a good way to go
Makes sense I will try something using that fingerprint thing.
Here, our doc on accepting a payment with just the card element shows how to set this flow up albeit with a payment intent instead of a setup intent. The calls/structure should be largely the same, you'll just use the setup intent calls instead https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=custom#ios-submit-payment
Also not sure if you have already considered it but we do generally recommend using the payment sheet as it is newer and more feature rich. Card Element is still totally usable and supported, just wanted to flag that https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet
This is helpful in what regards, sorry I just lost track of resources and their purpose
No worries, I needed to look it all up myself
Oh I see. I will notify my team
Sounds good, on that topic we actually have this doc specifically about saving payment methods with the payment sheet. It doesn't have a section on the card element flow but like I said that payment doc should be very similar https://stripe.com/docs/payments/save-and-reuse
Too many things to consider.
Thanks a lot.
I will revert with question if I have any.