Paypal集成php身份验证失败

时间:2019-03-10 15:19:05

标签: php api symfony paypal

我正在尝试将Paypal集成到我的网站中,但是当我上线并尝试在验证客户端后执行付款时,出现以下交易错误:

  

名称“ AUTHENTICATION_FAILURE”
  消息“由于身份验证凭据无效或缺少授权头而导致身份验证失败。”

但是它已经工作了2次,然后又没有了。

创建交易的代码:

public function genererPaiement(Inscription $inscri) {


    $apiContext = Paiement::getContexte();

    $payer = new Payer();
    $payer->setPaymentMethod('paypal');

    $items = array();
    $items[0] = $inscri->getCircuit()->getItem();
    $i = 1;
    foreach ($inscri->getOptionInscris() as $option) {
        $items[$i] = $option->getItem();
        $i++;
    }

    $itemList = new ItemList();

    $total = 0;
    for ($j = 0; $j < $i; $j++) {
        $total += floatval($items[$j]->getPrice()) * intval($items[$j]->getQuantity());
        $itemList->addItem($items[$j]);
    }

    $amount = new Amount();
    $amount->setCurrency('EUR')
        ->setTotal($total);

    $transaction = new Transaction();
    $transaction->setAmount($amount);
    $transaction->setItemList($itemList)
        ->setDescription("Paiement route thermale cycliste.")
        ->setInvoiceNumber($this->course->getId());

    $baseURL = Paiement::getBaseURL();
    $redirectURL = new RedirectUrls();
    $redirectURL->setReturnUrl($baseURL.'/engagement/'.$this->course->getId().'/'.$inscri->getId().'/true')
        ->setCancelUrl($baseURL.'/engagement/'.$this->course->getId().'/'.$inscri->getId().'/false');

    $payement = new Payment();
    $payement->setIntent('sale')
        ->setPayer($payer)
        ->setRedirectUrls($redirectURL)
        ->setTransactions(array($transaction))
        ->create($apiContext);

    return $payement->getApprovalLink();

}

要执行的代码:

public function payer($idEng, $idInscrit)
{
    $paymentId = $_GET['paymentId'];
    $apiContext = Paiement::getContexte();

    $payment = Payment::get($paymentId, $apiContext);

    $execution = new PaymentExecution();
    $execution->setPayerId($_GET['PayerID']);

    $result = $payment->execute($execution, $apiContext);

    $em = $this->getDoctrine()->getManager();
    $onglets = $em->getRepository(Onglets::class)->findOnglets();

    $eng = $em->getRepository(Engagement::class)->find($idEng);

    $page = $em->getRepository(Pages::class)->find(3);

    $inscri = $em->getRepository(Inscription::class)->find($idInscrit);

    $inscri->setPayer(true);

    return $this->render('engagement/index.html.twig', [
        "page" => $page,
        "onglets" => $onglets,
    ]);
}

0 个答案:

没有答案