Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save greenhornet79/671001e8603f2440ea6df38497b92d7e to your computer and use it in GitHub Desktop.
Save greenhornet79/671001e8603f2440ea6df38497b92d7e to your computer and use it in GitHub Desktop.
<?php
add_action('leaky_paywall_before_create_stripe_subscription', 'endo_handle_product_for_recurring_checkout', 20, 2);
function endo_handle_product_for_recurring_checkout($customer, $fields) {
$stripe = leaky_paywall_initialize_stripe_api();
try {
$invoice_item = $stripe->invoiceItems->create([
'customer' => $customer->id,
'amount' => 5000, // Amount in cents ($50.00 in this case)
'currency' => 'usd',
'description' => 'One-time fee for summer issue',
]);
} catch (\Throwable $th) {
leaky_paywall_log($user_id, 'leaky paywall - error creating invoice');
wp_send_json(array(
'error' => $th->jsonBody
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment