Skip to content

Commit

Permalink
chore: add support for subscription payments
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Aug 23, 2023
1 parent da58c72 commit 08dd607
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions plugins/otter-pro/inc/plugins/class-form-pro-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,29 @@ public function create_stripe_session( $form_data ) {

$payload['success_url'] = $permalink;
$payload['cancel_url'] = $permalink;


$stripe = new Stripe_API();

// Prepare the line items for the Stripe session request.
$line_items = array();
foreach ( $products_to_process as $product ) {
$line_items[] = array(
'price' => $product['price'],
'quantity' => 1,
);

if ( 'payment' === $payload['mode'] ) {
$price = $stripe->create_request( 'price', $product['price'] );
if ( is_wp_error( $price ) ) {
$form_data->set_error( Form_Data_Response::ERROR_STRIPE_CHECKOUT_SESSION_CREATION );
$form_data->add_warning( Form_Data_Response::ERROR_STRIPE_CHECKOUT_SESSION_CREATION, $price->get_error_message() );
return $form_data;
}

if ( 'recurring' === $price['type'] ) {
$payload['mode'] = 'subscription';
}
}
}
$payload['line_items'] = $line_items;

Expand All @@ -636,7 +651,7 @@ public function create_stripe_session( $form_data ) {

$payload['metadata'] = $metadata;

$stripe = new Stripe_API();


$session = $stripe->create_request(
'create_session',
Expand All @@ -645,6 +660,7 @@ public function create_stripe_session( $form_data ) {

if ( is_wp_error( $session ) ) {
$form_data->set_error( Form_Data_Response::ERROR_STRIPE_CHECKOUT_SESSION_CREATION );
$form_data->add_warning( Form_Data_Response::ERROR_STRIPE_CHECKOUT_SESSION_CREATION, $session->get_error_message() );
return $form_data;
}

Expand Down

0 comments on commit 08dd607

Please sign in to comment.