我在用支付包 https://github.com/Payum/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() 它会再次显示结帐付款表单,因此我使用 createToken() 代替,但是我面临另一个问题,即交易的状态是新的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)