簡體   English   中英

symfony2 payum paypal表達簡單的結賬

[英]symfony2 payum paypal express simple checkout

我是Payum的新手。 很多事情讓我很困惑。 我嘗試建立一個簡單的paypal快速結賬,就像Payum 文檔上的示例節目一樣。但是,當我嘗試處理付款時,它會顯示異常:

“名為my_paypal_express_checkout的Payum付款不存在.500內部服務器錯誤 - InvalidArgumentException”

這是配置:

payum:
security:
    token_storage:
        Acme\PaymentBundle\Entity\PayumSecurityToken:
            doctrine:
                driver: orm
storages:
    Acme\PaymentBundle\Entity\PaymentDetails:
        doctrine: 
            driver: orm

contexts:
    Ibase_paypal_express:
        paypal_express_checkout_nvp:
         ...codes...

以下是控制器中准備和完成操作的代碼:

public function preparePaypalAction(Request $request)
{
    $paymentName = 'ibase_paypal_express_checkout';

    $form = $this->createPurchaseForm();
    $form->handleRequest($request);
    if ($form->isValid()) {
        $data = $form->getData();

        $storage = $this->get('payum')->getStorage('Ibase\PaymentBundle\Entity\PaymentDetails');

        /** @var \Ibase\CartBundle\Entity\PaymentDetails $paymentDetails */
        $paymentDetails = $storage->createModel();
        $paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = $data['currency'];
        $paymentDetails['PAYMENTREQUEST_0_AMT'] = $data['amount'];//total amount ??
        $storage->updateModel($paymentDetails);

        $captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
            $paymentName,
            $paymentDetails,
            'payment_done' // the route to redirect after capture;
        );

        $paymentDetails['INVNUM'] = $paymentDetails->getId();
        $paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
        $paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
        $storage->updateModel($paymentDetails);

        return $this->redirect($captureToken->getTargetUrl());
    }
    return $this->render('PaymentBundle:PaypalExpress:paypalPrepare.html.twig', array(
        'form' => $form->createView(),
        'paymentName' => $paymentName
    ));
}

public function doneAction(Request $request)
{
    $token = $this->get('payum.security.http_request_verifier')->verify($request);

    $payment = $this->get('payum')->getPayment($token->getPaymentName());

    $status = new BinaryMaskStatusRequest($token);
    $payment->execute($status);

    if ($status->isSuccess()) {
        $this->getUser()->addCredits(100);
        $this->get('session')->getFlashBag()->set(
            'notice',
            'Payment success. Credits were added'
        );
    } else if ($status->isPending()) {
        $this->get('session')->getFlashBag()->set(
            'notice',
            'Payment is still pending. Credits were not added'
        );
    } else {
        $this->get('session')->getFlashBag()->set('error', 'Payment failed');
    }

    return $this->redirect('home');
}

 /**
 * @return \Symfony\Component\Form\Form
 */
protected function createPurchaseForm()
{
    return $this->createFormBuilder()
        ->add('amount', null, array(
            'data' => 1,
            'constraints' => array(new Range(array('max' => 2)))
        ))
        ->add('currency', null, array('data' => 'AUD'))
        ->getForm()
    ;
}

任何人都可以幫助我們欣賞!

看看你的YML文件

contexts:
    Ibase_paypal_express:

和你的代碼:

$paymentName = 'ibase_paypal_express_checkout';

注意大寫'我'和字符串名稱? 這兩個名稱/值應該相同。 所以要么

$paymentName = 'Ibase_paypal_express'; 

要么

contexts:
    ibase_paypal_express_checkout:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM