Level 63
Is it for a single payment or for a subscription ?
Not sure, but I think that the card is necessarily saved if it's a subscription.
While using stripe, the card for future usage is saving without asking user consent. I have implemented stripe using Epheremal key. The client said he need to be sked consent before saving it, I read stripe docs and followed same steps but couldn't find the issue.
iam using flutter as frontend
public function pay(Transaction $transaction): array
{
$customerId = $this->getCustomer($transaction);
$ephemeralKey = $this->getEphemeralKey($customerId);
$paymentIntent = $this->api()->paymentIntents->create([
'amount' => $transaction->amount * 100,
'currency' => 'AED',
'description' => 'ABCD',
'customer' => $customerId,
'setup_future_usage' => 'off_session',
]);
return $paymentIntent->toArray() + ['ephemeral_key' => $ephemeralKey->secret, 'stripe_customer_id' => $customerId, 'customer_session_client_secret' => null];
}
public function getCustomer(Transaction $transaction)
{
$transactionModel = $transaction->model;
if ($transactionModel instanceof Order) {
$model = $transactionModel->customer;
}
if ($transactionModel instanceof Subscription) {
$model = $transactionModel->merchant;
}
if ($model->stripe_customer_id) {
return $model->stripe_customer_id;
}
$customer = $this->api()->customers->create([
'name' => $model->name,
'email' => $model->email,
]);
$model->stripe_customer_id = $customer->id;
$model->save();
return $customer->id;
}
private function getEphemeralKey(mixed $customerId): EphemeralKey
{
return $this->api()->ephemeralKeys->create(
['customer' => $customerId],
['stripe_version' => '2024-09-30.acacia']
);
}
$paymentIntent = $this->api()->paymentIntents->create([
'amount' => $transaction->amount * 100,
'currency' => 'INR',
'description' => 'ABCD',
'customer' => $customerId,
'automatic_payment_methods'=> [
"enabled" => true
]
]);
$customer_session = $this->api()->customerSessions->create([
'customer' => $customerId,
'components' => [
'payment_element' => [
'enabled' => true,
'features' => [
'payment_method_save' => 'enabled',
'payment_method_save_usage' => 'on_session',
],
],
],
]);
issue fixed
Please or to participate in this conversation.