条带支付网关使用PayumBundle创建定期付款

时间:2015-03-20 14:50:20

标签: php symfony stripe-payments payum

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

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

1 个答案:

答案 0 :(得分:0)

我设法在PayumBundle& amp; 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 Payment Form,因此我使用了createToken(),但是我面临另一个问题,即交易状态是新的。