Created
April 29, 2022 17:58
-
-
Save greenhornet79/d6f1f212edbfda93b33d82f17158a220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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