bemoore
bemoore

Reputation: 94

Stripe Checkout for recurring donations of variable amounts

I am trying to use Stripe Checkout to allow users to set up a monthly recurring donation for an amount of their choosing. When I set up the Session, it provides the correct inputs to the Stripe form, however when I look in Subscriptions in the back end of Stripe, nothing is created, and it seems to just take a single payment. Here is my code:

   $checkout_values['success_url'] = $success_url;
   $checkout_values['cancel_url'] = $cancel_url;
   $checkout_values['payment_method_types'] = ['card','sepa_debit'];      
   $checkout_values['mode'] = 'subscription';
   $checkout_values['metadata']['order_id'] = $order_id;

   //Single line item for the dynamically created subscription and price info
   $line_item = [
         'price_data' => [
               'recurring' => [
                       'interval' => 'month',
                       'interval_count' => 1
                        ],
                'currency' => $order->get_currency(),
                'product_data' => [
                    'name' => $item->get_name()
                ],
               'unit_amount' => $item_total
               ],
           'quantity' => 1,
          ];
               
          $checkout_values['line_items'][] = $line_item;                
                                

Maybe I need to create a subscription in Stripe and tie that in? In which case why doesn't it give me an error?

Upvotes: 1

Views: 450

Answers (1)

qichuan
qichuan

Reputation: 2049

you don't need to explicitly create a subscription object. If you use Stripe Checkout, a subscription will be automatically created when your customer completed the payment flow in your checkout page.

You might want to firstly check if you are viewing the right mode (either Live or Test), and then take a look at the Dashboard Events to confirm subscription related events. You application can also listen to webhook events to get notified.

Upvotes: 1

Related Questions