I am using PayumBundle to integrate Stripe payment gateway to my symfony2 application.
i can create a successful direct payment, however i cannot create a recurring one. as the documentation of the bundle very poor.
My question is how to implement recurring payment for a customer using PayumBundle or any similar one.
I manage to do a small combination between PayumBundle & Stripe-php as following:
/**
* @Extra\Route(
* "/prepare_checkout",
* name="mycom_stripe_prepare_checkout"
* )
*
* @Extra\Template("MYCOMStripeBundle:PurchaseExamples:prepareCheckout.html.twig")
*/
public function prepareCheckoutAction(Request $request) {
$paymentName = 'subscribe_guardia_via_stripe_checkout';
$storage = $this->getPayum()->getStorage('MYCOM\PaymentBundle\Entity\PaymentDetails');
/** @var $details PaymentDetails */
$details = $storage->create();
$details["amount"] = 85 * 100;
$details["currency"] = 'USD';
$details["description"] = "Bi-Annual Subs.";
if ($request->isMethod('POST') && $request->request->get('stripeToken')) {
// create a new customer and assign a plan for him
\Stripe::setApiKey($this->container->getParameter('stripe.secret_key'));
$customer = \Stripe_Customer::create([
'description' => 'amr samy',
'source' => $request->request->get('stripeToken'),
'plan' => 'C1',
]);
$details["customer"] = $customer->id;
$storage->update($details); // presist the customer and the payment
$captureToken = $this->getTokenFactory()->createToken(
$paymentName, $details, 'mycom_subscription_create_stripe_recurring_payment'
);
return $this->redirect($captureToken->getTargetUrl());
}
return array(
'publishable_key' => $this->container->getParameter('stripe.publishable_key'),
'model' => $details,
'paymentName' => $paymentName
);
}
The only issue i am facing is if use createCaptureToken() it shows Checkout Payment Form again, hence i used createToken() instead, however gain i face another issue which is the status of the transaction is new.