#mani535-q

1 messages ยท Page 1 of 1 (latest)

lucid delta
#

hello there @robust forge

robust forge
#

I am facing problem to implement the saved cards feature

lucid delta
#

sure, what's the problem exactly?

robust forge
#

There is saved cards feature

#

but after the first transaction next on words

#

the prev used card should prefil

#

How can i do that

lucid delta
#

you'd use a Customer and an ephemeral key.

robust forge
#

We used this its not workign

lucid delta
#

can you say more? What does "not working" mean? Any examples I can look at like the exact code you're using or a Customer ID cus_xxx?

robust forge
#

cus_Lem2vJJyEsBPFX

#

Stripe customer id

lucid delta
#

that code is crashing, as should be able to tell.

robust forge
#

Okay let me try

#

card details not came

#

this trasaction got success

#

but this card for the next transaction not in the saved cards

lucid delta
#

you didn't pass setup_future_usage, so the card doesn't get saved to the Customer.

#

you can see how it uses setup_future_usage

robust forge
#

Okay checking

#

"setup_future_usage" => 'off_session'

when i set this

robust forge
lucid delta
#

yeah because you're forcing it to always be "on" basically.

robust forge
#

Now i am using this

#

"setup_future_usage" => 'on_session'

lucid delta
#

but yeah ok, you don't need to pass it on the backend

#

if the customer clicks that checkbox it should work and save their card too

#

which it did in the example you have

#

so I don't know what "but this card for the next transaction not in the saved cards" means, it will be there if you're using a new PaymentIntent with the same customer ID and the correct ephemeral key.

robust forge
#

i am using same customer id only

lucid delta
robust forge
#

Yes

lucid delta
#

cool. So what's the PaymentIntent pi_xxx of your most recent attempt to do a payment for that customer and hopefully see their saved cards?

robust forge
#

pi_3KxVIRATgVyy3rKC17rE3Ddi

#

hi

lucid delta
lucid delta
robust forge
#

you still didnt answer my last question pls

#

we arent able to save cards

#

this is my code

lucid delta
#

I'm working with you to answer your question.

robust forge
#

thanks pls check above code

lucid delta
#

yep, that's what I'm doing.....

robust forge
#

ok

lucid delta
#

so that PaymentIntent should work fine.

#

please share full context before replying again:

  • all your backend code. Not a screenshot, the full text. Make sure to remove your API key if it's there.
  • all your frontend code. Not a screenshot, the full text of the Android activity.
  • screenshot/video of what you see in the frontend.
robust forge
lucid delta
#

thanks, really helpful so far! Do you have the frontend code for the Android app and how it calls that backend?

#

@robust forge

robust forge
#

private fun startStripPayment(stripeJson: JSONObject) {
try {
if (stripeJson.has("stripe_customer_id") && stripeJson.has("ephemeral_key")) {
paymentIntentClientSecret = stripeJson.getString("payment_intent")
customerConfig = PaymentSheet.CustomerConfiguration(
stripeJson.getString("stripe_customer_id"),
stripeJson.getString("ephemeral_key")
)

            PaymentConfiguration.init(
                this,
                stripeJson.getString("publishable_key")
            )
        }
        if (stripeJson.has("payment_intent")) {
            paymentIntentClientSecret = stripeJson.getString("payment_intent")
        }
        openPaymentScreen()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

private fun openPaymentScreen() {
    val configuration = PaymentSheet.BillingDetails.Builder()
        .address(
            PaymentSheet.Address.Builder()
                .country("MT").build()
        ).build()

    if (customerConfig != null) {
        Log.d(
            TAG,
            "openPaymentScreen: Configuration completed"
        )
    }

    paymentSheet?.presentWithPaymentIntent(
        paymentIntentClientSecret!!, PaymentSheet.Configuration(
            merchantDisplayName = "All I Need",
            customer = customerConfig,
            googlePay = googlePayConfiguration,
            // Set `allowsDelayedPaymentMethods` to true if your
            // business can handle payment methods that complete payment
            // after a delay, like SEPA Debit and Sofort.
            allowsDelayedPaymentMethods = true,
            defaultBillingDetails = configuration
        )
    )
}
lucid delta
#

thanks, seems sensible, thinking...

robust forge
#

ok

lucid delta
#

also, please share the full code

#

that isn't all of it, since you don't show me how you create the paymentSheet variable

robust forge
lucid delta
#

thanks

#

testing some things...

#

ah I think the issue is you're passing the ephemeral key wrong.

You need to use the secret field of the object(it looks like ek_[test|live]_xxxx ).

I would change the backend function create_ephemeral_key from

  return [
                "ephemeralKey" => $ephemeralKey,
            ];

to

  return [
                "ephemeralKey" => $ephemeralKey->secret,
            ];
robust forge
#

Okay checking

#

Array
(
[err_code] => valid
[title] => Success
[message] => Order placed successfully
[ref_id] => 2022050991317
[payment_gateway_web_url] =>
[gateway_name] => Stripe
[total_paid] => no
[stripe_info] => stdClass Object
(
[payment_intent] => pi_3KxVyIATgVyy3rKC35BthceI_secret_jJqFzJbpb78drAlStTsw6WjiO
[ephemeral_key] => stdClass Object
(
[ephemeralKey] => ek_test_YWNjdF8xSFowVHJBVGdWeXkzcktDLFIwa1o1ekw0Mm1oVU45eTByeGk4RkN5cmhkZkFTVTU_00W9rPBqIh
)

        [stripe_customer_id] => cus_Lem2vJJyEsBPFX
        [publishable_key] => pk_test_51HZ0TrATgVyy3rKCvoAJ4gRjCslsGCma9smNjXG1PPMQtDJln4HL8C7qYptqcFDuCTid2Sq8yGu1RBito4CS08Pp00ixGTBria
    )

)

#

this is response

lucid delta
#

actually just change it to return $ephemeralKey->secret;

robust forge
#

function create_ephemeral_key($data) {
try {
$ephemeralKey = \Stripe\EphemeralKey::create(
['customer' => $data['customer_id']], ['stripe_version' => '2020-08-27']
);
/* $ephemeralKey = \Stripe\EphemeralKey::create([
'customer' => $data['customer_id'],
'stripe_version' => '2020-08-27'
]); */
return [
"ephemeralKey" => $ephemeralKey->secret,
];
} catch (Exception $e) {
$this->api_error = $e->getMessage();
return $this->api_error;
}
}

lucid delta
#

it would be much easier. Try that and then let me know what happens in the app when you call presentWithPaymentIntent

robust forge
#

yes i changed like you mentioned

lucid delta
robust forge
#

let me try

robust forge
#

fixed

#

thanks alot @lucid delta @meager bobcat much appriciated !!

lucid delta
#

great!