【问题标题】:Stripe payment gateway create recurring payment using PayumBundleStripe 支付网关使用 PayumBundle 创建定期支付
【发布时间】:2015-05-24 00:45:12
【问题描述】:

我正在使用PayumBundle 将 Stripe 支付网关集成到我的 symfony2 应用程序中。 我可以创建一个成功的直接付款,但是我不能创建一个经常性的。因为捆绑包的文档很差。

我的问题是如何使用 PayumBundle 或任何类似的方式为客户实施定期付款。

【问题讨论】:

  • Payum 未添加 Stripe 循环支付支持。我可以为您做,或者您可以自己做(发送 PR (;)。
  • 打扰一下,PR 是什么?
  • 抱歉,PR 是指拉取请求。
  • @MaksimKotlyar 检查我对问题的回答,非常感谢您的反馈
  • @MaksimKotlyar,公关:github.com/Payum/PayumBundle/issues/249

标签: php symfony stripe-payments payum


【解决方案1】:

我设法在 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() 代替,但是我面临另一个问题,即交易状态是新的。

【讨论】:

  • 尝试做一个转发而不是 $this->redirect($captureToken->getTargetUrl());或者将 stripeToken 保存到 details 中。
猜你喜欢
  • 2016-06-16
  • 2021-01-31
  • 2019-03-30
  • 2018-02-22
  • 2018-09-26
  • 2020-07-18
  • 2012-09-05
  • 2014-07-07
  • 1970-01-01
相关资源
最近更新 更多