php - “已经为此令牌创建了成功的计费协议。”
问题描述
我正在尝试在 Symfony 中使用Payum Bundle设置定期付款。需要有可能在一个订单中进行多次定期付款,并通过 Paypal Sandbox 仪表板判断,因为这PROFILE_START_DATE
是DATE_ATOM
初始付款,即使有多个项目,但是当我查看 Phpmyadmin 时,只有一个条目RecurringPaymentDetails
将具有"ACK": "Success"
和其余的将失败A successful Billing Agreement has already been created for this token.
我有一个处理逻辑的 OrderController,它设置扩展实体的值ArrayObject
/**
* @Route("/accounts/order/paypal/completed", name="order_paypal_completed")
*/
public function orderPaypalCompletedAction(Request $request)
{
$token = $this->get('payum')->getHttpRequestVerifier()->verify($request);
$identity = $token->getDetails();
$payment = $this->get('payum')->getStorage($identity->getClass())->find($identity);
$gateway = $this->get('payum')->getGateway($token->getGatewayName());
$gateway->execute($status = new GetHumanStatus($token));
$order = $payment->getOrder();
if ($status->isCaptured() || $status->isAuthorized()) {
$order->setStatus(Order::STATUS_COMPLETED);
$agreement = $status->getModel();
$storage = $this->get('payum')->getStorage(RecurringPaymentDetails::class);
$payments = [];
foreach ($order->getItems() as $item) {
$payment = $storage->create();
$payment['TOKEN'] = $agreement['TOKEN'];
$payment['DESC'] = $agreement['L_BILLINGAGREEMENTDESCRIPTION0'];
$payment['EMAIL'] = $agreement['EMAIL'];
$payment['AMT'] = $item->getPrice();
$payment['CURRENCYCODE'] = $order->getCurrency();
$payment['BILLINGFREQUENCY'] = $item->getDuration();
$payment['PROFILESTARTDATE'] = date(DATE_ATOM);
$payment['BILLINGPERIOD'] = Api::BILLINGPERIOD_DAY;
$payments[] = $payment;
}
$this->addFlash('success', $this->get('translator')->trans('Payment has been successful.'));
}
if ($status->isPending()) {
$this->addFlash('danger', $this->get('translator')->trans('Payment has been canceled.'));
}
if ($status->isFailed() || $status->isCanceled()) {
$order->setStatus(Order::STATUS_CANCELED);
$this->addFlash('danger', $this->get('translator')->trans('Payment has been canceled.'));
}
foreach ($payments as $payment) {
$gateway->execute(new CreateRecurringPaymentProfile($payment));
$gateway->execute(new Sync($payment));
$recurringPaymentStatus = new GetHumanStatus($payment);
$gateway->execute($recurringPaymentStatus);
}
try {
$em = $this->getDoctrine()->getManager();
$em->persist($order);
$em->flush();
} catch (\Exception $e) {
$this->addFlash('danger', $this->get('translator')->trans('An error occurred when saving object.'));
}
return $this->redirectToRoute('homepage');
}
有了这个,我觉得,如果只能从贝宝返回一个令牌,我必须将它们重定向回贝宝,因为每个项目都是胡说八道。有没有办法可以复制每个项目的令牌或者你有什么建议?
解决方案
环顾四周,我发现这很明显我必须为每个订阅将它们重定向到 Paypal。有点费力,但显然这是唯一的方法。
编辑:我很快就谈到了,这个问题与同一结帐中的不同类型的计费协议有关,我的问题是针对具有相同条件的多个计费协议。
推荐阅读
- symfony - Symfony Messenger / RabbitMQ 中的消费者错误处理
- filter - 根据计数和存储值的组合计算百分比 - Power BI
- multithreading - 如何构建在球拍 lisp 引擎中使用的程序?
- python - Pandas 将两行合二为一
- c# - 当相机透视像 Matlab 视图一样发生变化时,修改 WPF 中绘制的轴上的 3D 坐标
- kubernetes - 无法将 kubernetes-bionic main (Ubuntu 18.04) 添加到 apt 存储库
- php - Doctrine AnnotationRegistry registerLoader替换
- angularjs - AngularJS - 使用'track by $index'时下拉过滤不会更新
- wordpress-gutenberg - 如何使用 php $content 在 Gutenberg 版本 4 中渲染 InnerBlocks
- eclipse - 从代理后面,我可以在 Eclipse 市场中找到东西,但无法安装它们