2016-02-12 175 views
0

授权失败授权失败[Omnipay和Paypal]

这里是我的代码:

$gateway = Omnipay::create('PayPal_Express'); 

     // Initialise the gateway 
     $gateway->initialize(array(
      'clientId' => 'AZzCeImpURKHH0LIFSBTrEWGY-NKLCnUUQdHT049pRLvwBXg9BnlpbnsiGLPFQH43DU4eL-Qi96nrZU6', 
      'secret' => 'EFP_mny9dfaaAfW1oyNM8R05weA5eIkU51KUSAdbvcoh3v4bo7txRBm-uzDZ2nOlZ0KmqS-JalgujFok', 
      'testMode' => true, // Or false when you are ready for live transactions 
     )); 

     // Do an authorisation transaction on the gateway 
     $transaction = $gateway->authorize(array(
      'returnUrl' => 'http://client.com', 
      'cancelUrl' => 'http://localhost:8000/cancel', 
      'amount' => '10.00', 
      'currency' => 'AUD', 
      'description' => 'This is a test authorize transaction.', 
       // 'card'   => $card, 
     )); 

     $response = $transaction->send(); 
     if ($response->isSuccessful()) { 
      // Find the authorization ID 
      $authResponse = $response->getTransactionReference(); 
      echo "Authorize transaction was successful!\n" . $authResponse; 
     } else { 
      echo "Failed to auth transaction"; 
      dd($response); 
     } 

     // Once the transaction has been approved, we need to complete it. 
     $transaction = $gateway->completePurchase(array(
      'payerId' => $request->PayerID, 
      'transactionReference' => $authResponse 
     )); 

     $finalResponse = $transaction->send(); 

     dd($finalResponse); 

     if ($finalResponse->getData()) { 
      echo "Transaction was successful!\n"; 
      // Find the authorization ID 
      $results = $finalResponse->getTransactionReference(); 
      dd($results); 
     } else { 
      dd($finalResponse->getData()); 
     } 

我试图建立贝宝sendbox我laravel应用程序。此代码是GET方法,当我把它称为我得到:

Failed to auth transaction 
ExpressAuthorizeResponse {#354 ▼ 
    #liveCheckoutEndpoint: "https://www.paypal.com/cgi-bin/webscr" 
    #testCheckoutEndpoint: "https://www.sandbox.paypal.com/cgi-bin/webscr" 
    #request: ExpressAuthorizeRequest {#349 ▶} 
    #data: array:9 [▼ 
    "TIMESTAMP" => "2016-02-12T15:06:21Z" 
    "CORRELATIONID" => "68efe51d8aca6" 
    "ACK" => "Failure" 
    "VERSION" => "119.0" 
    "BUILD" => "18308778" 
    "L_ERRORCODE0" => "10002" 
    "L_SHORTMESSAGE0" => "Authentication/Authorization Failed" 
    "L_LONGMESSAGE0" => "You do not have permissions to make this API call" 
    "L_SEVERITYCODE0" => "Error" 
    ] 
} 

任何人都知道是什么问题呢?由于

回答

0

返回错误代码是10002:"L_ERRORCODE0" => "10002"

贝宝API Error and Warning Codes文件规定:

这种错误可能是由不正确的API的用户名,不正确的 API的密码,或者无效引起的API签名。确保所有这三个 这些值都是正确的。为了您的安全,PayPal不会准确报告 这三个值中的哪一个可能会出错。

API用户名和/或密码错误。重置这些并重试。

0

传递给initialize()方法的数组结构将用于REST API。

变化:

$gateway = Omnipay::create('PayPal_Express');

到:

$gateway = Omnipay::create('PayPal_Rest');

你可以通过调用getDefaultParameters()方法获取可用参数列表。

对于PayPal_Rest它将会给你:

array:4 [▼ 
    "clientId" => "" 
    "secret" => "" 
    "token" => "" 
    "testMode" => false 
] 

这对于PayPal_Express

array:10 [▼ 
    "username" => "" 
    "password" => "" 
    "signature" => "" 
    "testMode" => false 
    "solutionType" => array:2 [▶] 
    "landingPage" => array:2 [▶] 
    "brandName" => "" 
    "headerImageUrl" => "" 
    "logoImageUrl" => "" 
    "borderColor" => "" 
]