1

我正在尝试在 Symfony 2 上使用 Payum 将计划附加到 Stripe 费用。我能够成功地从卡上收费,但我不明白如何将计划添加到费用中。

我开始研究直接使用 Stripe_Customer 对象,而不是使用 Payum,但我在获取 Stripe 令牌时遇到了麻烦。我向付款对象添加了一个计划方法。任何帮助将不胜感激!

<?php
namespace SEC\PaymentBundle\Controller;
use Payum\Core\Model\CreditCard;
use Payum\Core\Request\GetHttpRequest;
use Payum\Stripe\Action\Api\ObtainTokenAction;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use SEC\PaymentBundle\Entity\Payment;
use Payum\Core\Request\GetHumanStatus;
use Payum\Stripe\Request\Api\CreateCustomer;
use Payum\Stripe\StripeJsGatewayFactory;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class PaymentController extends Controller
{
    public function prepareAction(Request $request)
    {
        $factory = new StripeJsGatewayFactory();
        $gateway = $factory->create(array(
            'publishable_key' => '****',
            'secret_key' => '****',
        ));
        $card = new \Payum\Core\Model\CreditCard();
        $card->setNumber('4111111111111111');
        $card->setExpireAt(new \DateTime('2018-10-10'));
        $card->setSecurityCode('123');
        $card->setHolder('Test');
        $customer = new \Stripe_Customer();
        $storage = $this->get('payum')->getStorage('SEC\PaymentBundle\Entity\Payment');
        $model = $storage->create();
        $model->setNumber(uniqid());
        $model->setCurrencyCode('USD');
        $model->setTotalAmount(100);
        $model->setClientId($this->getUser());
        $model->setDateCreated(new \DateTime('now'));
        $model->setClientEmail('test@gmail.com');
        $model->setCreatedBy($this->getUser());
        $model->setCreditCard($card);
        $model->setCustomer($customer);
        $model->setDescription('This is a description');
        $model->setPlan(1);
        $storage->update($model);
        $gateway->execute(new \Payum\Core\Request\Capture($model));
        $captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
            'offline',
            $model,
            'done' // the route to redirect after capture
        );
        return $this->render('SECPaymentBundle:Default:debug.html.twig', array(
            'model2' => $model,
            'model' => $captureToken,
            'model3' => ''
        ));
    }
4

2 回答 2

2

我目前正在研究它,已经有一个CreateCustomerAction可以重复使用的。

因此,在CreateCustomerAction创建客户之后,您必须将cust_XXXX令牌添加到模型中,以便以后用作收费源(而不是卡)。

但这需要某种不同的工作流程/操作。

于 2016-02-22T02:09:26.847 回答
1

它在文档中进行了解释。

为客户订阅计划

这是一种常见的收费,因为我们在 get-it-started 中展示了它,仅添加了以下内容:

<?php // prepare.php

/** @var \Payum\Core\Model\PaymentInterface $payment */

$payment->setDetails([
    'amount' => 2000,
    'currency' => 'USD',

    // everything in this section is never sent to the payment gateway
    'local' => [
        'save_card' => true,
        'customer' => ['plan' => $plan['id']],
    ], ]);

正如您在array传递给$payment->setDetails()方法中看到的那样,键local有一个子键customer:这个子键接受一个数组,并在其中设置plan具有相应计划 ID 在 Stripe 上的键将使客户订阅该计划。

于 2016-09-15T12:32:10.047 回答