How to managed custom amount based plans code in stripe payment?
Plan id : basic-{interval}-{amount}
1) Check plan exits or not ?
if : exits then assign to subscriber
not - Create a new plan.
if(!empty($recurring_duration)){
try {
$plan = \Stripe\Plan::retrieve($planname);
} catch (Error\InvalidRequest $exception) {
$plan = \Stripe\Plan::create(array(
"name" => "Basic Plan",
"id" => $planname,
"interval" => "$recurring_duration",
"currency" => strtolower($currency),
"amount" => $amount,
));
}
$plan = \Stripe\Plan::create(array(
"name" => "Basic Plan",
"id" => $planname,
"interval" => "$recurring_duration",
"currency" => strtolower($currency),
"amount" => $amount,
));
}
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $token
));
if(!empty($recurring_duration)){
$charge = \Stripe\Subscription::create(array(
"customer" => $customer->id,
"items" => array(
array(
"plan" => $planname,
),
),
));
}else{
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => strtolower($currency),
'description' => '',
)
);
}
$val = BSP_add_form_data($charge);