#subhan_22659

1 messages · Page 1 of 1 (latest)

tidal kernelBOT
abstract skiff
#

Hi! Let me help you with this.

#

Could you please share the Subscription ID?

rugged sparrow
#

sub_1NcRs3GjLUhGYSPpl78AjG1R

abstract skiff
#

This Subscription doesn't have a Payment Method so it couldn't pay the Invoice, that's why it's cancelled.

rugged sparrow
#

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);
}
abstract skiff
rugged sparrow
#

provide modified code please

abstract skiff
#

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.

rugged sparrow
#

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);
}
abstract skiff
#

In the webhook

rugged sparrow
#

ok let me test it