Last active
November 11, 2021 17:39
-
-
Save wpfullstripe/ff16c4886540fb50a73e622b2c9658e1 to your computer and use it in GitHub Desktop.
The fullstripe_before_subscription_charge Wordpress action
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 | |
/** | |
* A 'fullstripe_before_subscription_charge' action hook example for WP Full Stripe. | |
* It blocks the subscripton if the quantity is less than 3. | |
* | |
* @param array $params with the following keys: | |
* email => Email address of the customer | |
* urlParameters => Array of URL parameters | |
* formName => Name of the form the payment is being made on | |
* productName => Name of the Stripe product being purchased | |
* planId => Id of Stripe recurring price being purchased | |
* currency => ISO code of the payment currency (eg. USD) | |
* amount => Plan amount (it's in cents for non-zerodecimal currencies like the USD, EUR) | |
* setupFee => Setup fee amount (it's in cents for non-zerodecimal currencies like the USD, EUR). Zero if there is no setup fee. | |
* quantity => Number of plans purchased | |
* stripeClient => Instance of the \StripeWPFS\StripeClient object, intialized in the same API mode as the current transaction | |
*/ | |
function beforeInlineSubscriptionCharge( $params ) { | |
$amount = $params['quantity']; | |
if ( $quantity < 3 ) { | |
$ex = new WPFS_UserFriendlyException( "Please purchase at least 3 subscriptions" ); | |
$ex->setTitle( 'Not allowed' ); | |
throw $ex; | |
} | |
} | |
add_action('fullstripe_before_subscription_charge', 'beforeInlineSubscriptionCharge', 10 , 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment