#thiagomacauba88
1 messages ยท Page 1 of 1 (latest)
hey karbi
I think this was the original thread: https://discord.com/channels/841573134531821608/994218717942648902
yes
Can you give me a sense on where you left off / summarize the question? There's a lot of context to read through and i'll be able to help you faster if you give a summary
ok
i'd like to test apple payment flow.
i notice after try to charge by applePay, the method didCreatePaymentMethdod is called
I already have my implementation to charge card without apple pay using this one:
STPAPIClient.shared.createPaymentMethod(with: paymentMethodParams) { (paymentMethod, error) in
and i get the parameters from here:
let paymentMethodCardParams = STPPaymentMethodCardParams(cardSourceParams: cardParams)
let billingDetails = STPPaymentMethodBillingDetails()
let paymentMethodParams = STPPaymentMethodParams(card: paymentMethodCardParams, billingDetails: billingDetails, metadata: nil)
and I would like to see any examples using applePay
because the parameters are differents
Just to confirm I'm understanding this correctly - you're creating Payment Methods through the iOS sdk and you're trying to see how to just create the Payment Method through Apple Pay?
exacly
I don't think there's a simple way to get this - Apple Pay encrypts the payment data, and there's no way to decrypt it client-side to generate a Payment Method. You'd have to either decrypt it yourself, or send that information to us in a separate server-side request
I really wouldn't recommend doing it this way if you don't need to - it's a complicated flow, and we don't have examples for it
and if i not pass in my current flow?
What do you mean by that?
We walk through that in our docs (https://stripe.com/docs/apple-pay?platform=ios#create-payment-request) - have you taken a look at these?
let me check
What issue are you having?
I don't know what i need to do, does i need to create a paymentIntent?
Hi there ๐ taking over for @tidal lance
Give me a few minutes to get caught up.
Alright I'm up to speed. Is there an outstanding question here? What problem are you running into?
Just want to hop in with one thing - I do see one thing that may help you that I missed the first time @clever rock . I think you can actually use the 'paymentMethod': https://github.com/stripe/stripe-ios/blob/afc1f925ee1c70d4b37e3b727a90cfb946288a36/StripeApplePay/StripeApplePay/Source/ApplePayContext/STPApplePayContext.swift#L51
I don't believe you need to call 'createPaymentMethod' again - we already have create the Payment Method for you. You can use paymentMethod.id and pass that into your Payment Intent
you mean here:
STPPaymentHandler.shared().handleNextAction(forPayment: clientSecret, with: self, returnURL: nil) { (status, paymentIntent, err) in
I'm a little bit lost in this part
Yeah let me back up for a minute and start from the beginning
So with the ApplePayContextDelegate, the idea is that you implement https://stripe.dev/stripe-ios/docs/Protocols/ApplePayContextDelegate.html#/s:14StripeApplePay0bC15ContextDelegateP05applecD0_22didCreatePaymentMethod18paymentInformation10completionyAA08STPApplecD0C_0A4Core0A3APICAAE0iJ0VSo9PKPaymentCySSSg_s5Error_pSgtctF - in that method you'll get back a Payment Method (that you can choose to pass directly to your server if you create Payment Intent with 'confirmation_method: manual' and 'confirm: true'). As you've noticed - you need to also call the completion block with a Payment Intent or Setup Intent client secret
You either use the completion block to have stripe do the confirmation for you client-side, or you do the confirmation yourself server-side (as I mentioned with the 'confim: true' and 'confirmation_method: manual') and just call the completion block to signal that it was successful
Does that make sense?
unfortunately no
i have this until now
Alamofire.request("(StripeManager.baseURL())/setup_intent", method: .get, parameters: ["stripeAccount": accountId]).responseJSON(completionHandler: { (response) in
if let code = response.response?.statusCode, code <= 202 {
if let result = response.result.value, let json = result as? JSON {
if let clientSecret = json["intent_client_secret"] as? String {
print(clientSecret)
}
}
}
})
Where is that code from? Up until now you've only shared Payment Intent code? Why do you have Setup Intent code now?
my code
according to the doc
i need to to this
//let clientSecret = ... // Retrieve the PaymentIntent client secret from your backend (see Server-side step above)
// Call the completion block with the client secret or an error
//completion(clientSecret, error);
Yeah, so in the code you shared earlier you had a request to your backend to create a Payment Intent and confirm it:
Alamofire.request("\(StripeManager.baseURL())/confirm_payment?test-mode=\(isTestMode)", method: .post, parameters: params, encoding: JSONEncoding.default).responseJSON(completionHandler: { (response) in
After you make that request you'd just take the client_secret of that PaymentIntent and pass that into the completion block:
completion (clientSecret, error);
ok, but for call the confirmPayment i need this parameters
let params = [
"receipt_email": email ?? "",
"description": description ?? "",
"amount": self.adjust(amount: amount * 100.0, for: currencyCode).int(),
"payment_method_id": paymentMethod!.stripeId,
"user_account": accountId,
"currency_code": currencyCode,
"device_os": UIDevice.current.systemName,
"device_model": UIDevice.current.model,
"input_source": source ?? "",
"reader_used": readerUsed ?? false,
"authorize_only": authorizeOnly
] as [String: Any]
let me try
1 min
@clever rock How's it going?
the weird is, in my method i don't receive any error
i'm calling the completion like this
completion(clientSecret, nil)
maybe it's wrong
the error in callback delegate
The provided PaymentMethod was previously used with a PaymentIntent without Customer attachment, shared with a connected account without Customer attachment, or was detached from a Customer. It may not be used again. To use a PaymentMethod multiple times, you must attach it to a Customer first.
any ideas?
Ah, can you share the Payment Intent ID? I just want to check something
Apparently my payment intent id is null
i need to leave the office, can you try again tomorrow?
You may have to talk to someone else if it's tomorrow, but yes, if you need to leave now you can always ask again.
When you come back be sure to come with a Payment Intent ID as an example ๐
I don't accept private messages, but definitely come back tomorrow and someone can help! We're basically almost there, anyone will be able to help
๐