[英]Create a recurring or subscription payment using Payum Stripe on Symfony 2
[英]Stripe payment gateway create recurring payment using PayumBundle
我正在使用PayumBundle將Stripe支付網關集成到我的symfony2應用程序中。 我可以創建成功的直接付款,但是我不能創建定期付款。 由於捆綁包的文檔非常差。
我的問題是如何使用PayumBundle或任何類似的方式為客戶實施定期付款。
我設法在PayumBundle和Stripe-php之間做一個小組合,如下所示:
/**
* @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
);
}
我面臨的唯一問題是,如果使用createCaptureToken()再次顯示Checkout付款形式,因此我改用createToken(),但是我面臨另一個問題,即交易狀態是新的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.