首页 > 解决方案 > “已经为此令牌创建了成功的计费协议。”

问题描述

我正在尝试在 Symfony 中使用Payum Bundle设置定期付款。需要有可能在一个订单中进行多次定期付款,并通过 Paypal Sandbox 仪表板判断,因为这PROFILE_START_DATEDATE_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');
}

有了这个,我觉得,如果只能从贝宝返回一个令牌,我必须将它们重定向回贝宝,因为每个项目都是胡说八道。有没有办法可以复制每个项目的令牌或者你有什么建议?

标签: phpsymfonypaypalpayum

解决方案


环顾四周,我发现很明显我必须为每个订阅将它们重定向到 Paypal。有点费力,但显然这是唯一的方法。

编辑:我很快就谈到了,这个问题与同一结帐中的不同类型的计费协议有关,我的问题是针对具有相同条件的多个计费协议。


推荐阅读