#thiagomacauba88

1 messages ยท Page 1 of 1 (latest)

tidal lance
#

Hello! Starting a new thread for you - what's your question?

clever rock
#

hey karbi

jovial tangle
clever rock
#

yes

tidal lance
#

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

clever rock
#

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

tidal lance
#

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?

clever rock
#

exacly

tidal lance
#

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

clever rock
#

and if i not pass in my current flow?

tidal lance
#

What do you mean by that?

clever rock
#

suppose that i don't have this createPaymentMethod implemented

#

how could i charge?

tidal lance
clever rock
#

let me check

clever rock
#

I'm following this one

#

right now my issue is on step 8

tidal lance
#

What issue are you having?

clever rock
#

I don't know what i need to do, does i need to create a paymentIntent?

raven ridge
#

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?

clever rock
#

Hey two-shoes

#

I'm implementing applepay

tidal lance
clever rock
#

this is my method to charge

tidal lance
#

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

clever rock
#

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

tidal lance
#

Yeah let me back up for a minute and start from the beginning

clever rock
#

According to the documentation a i need to get the clientSecret, ok

#

and after this?

tidal lance
#

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

clever rock
#

let me check

#

so how is the method to charge?

tidal lance
#

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?

clever rock
#

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)
}
}
}
})

tidal lance
#

Where is that code from? Up until now you've only shared Payment Intent code? Why do you have Setup Intent code now?

clever rock
#

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);

tidal lance
#

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);

clever rock
#

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

tidal lance
#

@clever rock How's it going?

clever rock
#

well

#

it's charging

#

but its returing error

tidal lance
#

What error?

#

Can you share a Payment Intent ID?

clever rock
#

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?

tidal lance
#

Ah, can you share the Payment Intent ID? I just want to check something

clever rock
#

Apparently my payment intent id is null

#

i need to leave the office, can you try again tomorrow?

tidal lance
#

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 ๐Ÿ‘

clever rock
#

but i can send a private message tomorrow

#

i think is better we are almost there

tidal lance
#

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

clever rock
#

I'll tag you tomorrow in a channel, if you can help

#

thanks a lot

tidal lance
#

๐Ÿ‘