Subscription Billing
In this chapter we show how to create subscription plan and use it in future to charge a customer.
Create a plan
<?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));
or with existing product, for example Stripe API - Create a Plan
<?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
This is a usual charge as we showed it in get-it-started with only these additions:
<?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']],
],
]));
Links
Supporting Payum
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:
Last updated