#mani535-q
1 messages ยท Page 1 of 1 (latest)
I am facing problem to implement the saved cards feature
sure, what's the problem exactly?
There is saved cards feature
but after the first transaction next on words
the prev used card should prefil
How can i do that
you'd use a Customer and an ephemeral key.
if you initialise the PaymentSheet with a Customer+Ephemeral Key for a customer that already has saved payment methods, they'll be shown. https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=payment-sheet#add-server-endpoint
We used this its not workign
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?
that code is crashing, as should be able to tell.
see https://dashboard.stripe.com/test/logs/req_TJl0WuytsffHxl for example, or look at the logs since you would have caught this in the try/catch block.
Okay let me try
card details not came
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
this trasaction got success
but this card for the next transaction not in the saved cards
you didn't pass setup_future_usage, so the card doesn't get saved to the Customer.
https://stripe.com/docs/payments/save-during-payment?platform=android&ui=payment-sheet#add-server-endpoint is probably a better guide here
you can see how it uses setup_future_usage
the check box is not displaying
yeah because you're forcing it to always be "on" basically.
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
as you can see on https://dashboard.stripe.com/test/customers/cus_Lem2vJJyEsBPFX
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.
i am using same customer id only
did you fix this?
Yes
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?
thanks, looking
hi?
you still didnt answer my last question pls
we arent able to save cards
this is my code
what exactly do you think I'm doing in this thread?
I'm working with you to answer your question.
thanks pls check above code
yep, that's what I'm doing.....
ok
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.
thanks, really helpful so far! Do you have the frontend code for the Android app and how it calls that backend?
@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
)
)
}
thanks, seems sensible, thinking...
ok
also, please share the full code
that isn't all of it, since you don't show me how you create the paymentSheet variable
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,
];
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
actually just change it to return $ephemeralKey->secret;
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;
}
}
it would be much easier. Try that and then let me know what happens in the app when you call presentWithPaymentIntent
yes i changed like you mentioned
yeah, but change it again to just
return $ephemeralKey->secret;
with the way the rest of your code is set up that would probably work better.
let me try
great!