【发布时间】:2019-01-07 17:29:06
【问题描述】:
我正在尝试在 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');
}
有了这个,我觉得,如果只能从贝宝返回一个令牌,我必须将它们重定向回贝宝,这是无意义的。有没有办法可以复制每个项目的令牌或您有什么建议?
【问题讨论】: