Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created April 29, 2022 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenhornet79/d6f1f212edbfda93b33d82f17158a220 to your computer and use it in GitHub Desktop.
Save greenhornet79/d6f1f212edbfda93b33d82f17158a220 to your computer and use it in GitHub Desktop.
<?php
add_action('leaky_paywall_after_create_recurring_customer', 'zeen101_add_fee_to_recurring_checkout');
function zeen101_add_fee_to_recurring_checkout( $customer ) {
$fee_amount = 999; // in cents
$stripe = leaky_paywall_initialize_stripe_api();
try {
$invoice_item = $stripe->invoiceItems->create([
'amount' => $fee_amount,
'currency' => leaky_paywall_get_currency(),
'customer' => $customer->id,
'description' => 'Sign up fee',
]);
$invoice = $stripe->invoices->create([
'customer' => $customer->id,
'auto_advance' => true, /* auto-finalize this draft after ~1 hour */
]);
} catch (\Throwable $th) {
leaky_paywall_log($customer, '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