#subhan_22659
1 messages · Page 1 of 1 (latest)
sub_1NcRs3GjLUhGYSPpl78AjG1R
This Subscription doesn't have a Payment Method so it couldn't pay the Invoice, that's why it's cancelled.
But I have attached payment method using webhook setupIntentSucceeded event
protected function handleSetupIntentSucceeded(array $payload)
{
$obj = $payload['data']['object'];
$this->stripe->paymentMethods->attach(
$obj['payment_method'],
['customer' => $obj['customer']]
);
$data = [
'payment_status' => $obj['status']
];
Subscription::where('payment_intent', $obj['client_secret'])->update($data);
return response(['data' => $obj, 'message' => 'This is Setup Intent Object!'], 200);
}
You don't need to attach the Payment Method, what you need to do instead is set invoice_settings.default_payment_method: https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
provide modified code please
Sorry, can't write code for you, but I can point you in the right direction. You can find the code snippet of how to update a Customer object in PHP in the link I shared.
Just tell me
should I invoice_settings.default_payment_method:
in this method:
public function createSubscription($input)
{
$user = User::UserById($this->user->id, ['id','stripe_id'])->first();
if ($user) {
try {
$customer_id = $user->stripe_id;
if (is_null($user->stripe_id)) {
$customer_id = $this->createCustomer();
}
$subscriptionPayload = [
'customer' => $customer_id,
'items' => [
['price' => $input['plan_id']],
],
'payment_behavior' => 'default_incomplete',
'payment_settings' => ['save_default_payment_method' => 'on_subscription'],
'trial_settings' => ['end_behavior' => ['missing_payment_method' => 'cancel']],
];
Or in webhook:
protected function handleSetupIntentSucceeded(array $payload)
{
$obj = $payload['data']['object'];
$this->stripe->paymentMethods->attach(
$obj['payment_method'],
['customer' => $obj['customer']]
);
$data = [
'payment_status' => $obj['status']
];
Subscription::where('payment_intent', $obj['client_secret'])->update($data);
return response(['data' => $obj, 'message' => 'This is Setup Intent Object!'], 200);
}
In the webhook
ok let me test it