我正在尝试使用Symfony 2上的Payum附加计划收费。我能够成功收取卡,但我不明白如何将计划添加到收费中。
我开始考虑直接使用Stripe_Customer对象,而不是使用Payum,但是我在获取Stripe Token时遇到了麻烦。我在付款对象中添加了计划方法。任何帮助将不胜感激!
<?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' => ''
));
}
答案 0 :(得分:2)
我正在研究它,已经有CreateCustomerAction
可以重复使用了。
因此,在CreateCustomerAction
创建客户之后,您必须将cust_XXXX
令牌添加到模型中,以后可以将其用作充电源(而不是卡)。
但这需要某种不同的工作流程/行动。
答案 1 :(得分:0)
documentation中解释了这一点。
订阅客户计划
这是我们展示的常用费用 只使用这些新增功能开始:
<?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
:此子项接受一个数组并在其中设置密钥带有Stripe上相应计划ID的plan
会将客户订阅到该计划。