In this chapter we show how to create subscription plan and use it in future to charge a customer.
Copy <?php
// prepare.php
use Payum\Stripe\Request\Api\CreatePlan;
$plan = new \ArrayObject([
"amount" => 2000,
"interval" => "month",
"currency" => "usd",
"id" => "gold",
"product" => [
"name" => "Amazing Gold Plan"
]
]);
/** @var \Payum\Core\Payum $payum */
$payum->getGateway('gatewayName')->execute(new CreatePlan($plan));
Copy <?php
// prepare.php
use Payum\Stripe\Request\Api\CreatePlan;
$plan = new \ArrayObject([
"amount" => 2000,
"interval" => "month",
"currency" => "usd",
"id" => "gold",
"product" => "prod_NjpI7DbZx6AlWQ" // Product ID
]);
/** @var \Payum\Core\Payum $payum */
$payum->getGateway('gatewayName')->execute(new CreatePlan($plan));
Subscribing a customer to a plan
Copy <?php
// prepare.php
/** @var \Payum\Core\Model\PaymentInterface $payment */
$payment->setDetails(new \ArrayObject([
'amount' => 2000,
'currency' => 'USD',
// everything in this section is never sent to the payment gateway
'local' => [
'save_card' => true,
'customer' => ['plan' => $plan['id']],
],
]));
Payum is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider: