簡體   English   中英

Omnipay Paypal Express Checkout 錯誤:安全標頭無效

[英]Omnipay Paypal Express Checkout Error: Security header is not valid

每當使用 setTestMode() 方法時,都會彈出錯誤“安全標頭無效”。

但是如果我刪除 setTestMode() 並只保留 setUsername()、setPassword() 和 setSignature() 方法,它會通過並直接重定向到 PayPal (Live Paypal)。

所以 AFAIK 問題應該在於我如何使用 setTestMode 而不是關於不正確的 API 憑據,因為大多數“安全標頭無效”錯誤是關於。

我目前正在使用 Laravel 5.8 和 Omnipay/PayPal 使用 PayPal Express Checkout

這是使用的文件

支付寶

public function gateway()
{
    $gateway = Omnipay::create('PayPal_Express');

    $gateway->setUsername(config('services.paypal.username'));
    $gateway->setPassword(config('services.paypal.password'));
    $gateway->setSignature(config('services.paypal.signature'));
    $gateway->setTestMode(config('services.paypal.sandbox'));
    // $gateway->setTestMode(true);

    return $gateway;
}

public function purchase(array $parameters)
{
    $response = $this->gateway()
        ->purchase($parameters)
        ->send();

    return $response;
}

支付寶控制器.php

public function checkout($order_id)
{
    $order = Order::findOrFail(decrypt($order_id));

    $paypal = new PayPal;

    $response = $paypal->purchase([
        'amount' => $paypal->formatAmount($order->amount),
        'transactionId' => $order->transaction_id,
        'currency' => 'PHP',
        'cancelUrl' => $paypal->getCancelUrl($order),
        'returnUrl' => $paypal->getReturnUrl($order),
        'notifyUrl' => $paypal->getNotifyUrl($order),
    ]);

    if ($response->isRedirect()) {
        $response->redirect();
    }

    return redirect()->back()->with([
            'message' => $response->getMessage(),                
    ]);
}

這是 $response 的內容

ExpressAuthorizeResponse {#1098 ▼
  #liveCheckoutEndpoint: "https://www.paypal.com/cgi-bin/webscr"
  #testCheckoutEndpoint: "https://www.sandbox.paypal.com/cgi-bin/webscr"
  #request: ExpressAuthorizeRequest {#1095 ▼
    #liveEndpoint: "https://api-3t.paypal.com/nvp"
    #testEndpoint: "https://api-3t.sandbox.paypal.com/nvp"
    #negativeAmountAllowed: true
    #parameters: ParameterBag {#1097 ▶}
    #httpClient: Client {#1063 ▶}
    #httpRequest: Request {#1086 ▶}
    #response: ExpressAuthorizeResponse {#1098}
    #currencies: ISOCurrencies {#1096}
    #zeroAmountAllowed: true
  }
  #data: array:9 [▼
    "TIMESTAMP" => "2020-02-03T11:04:45Z"
    "CORRELATIONID" => "c8d066c9b5ccd"
    "ACK" => "Failure"
    "VERSION" => "119.0"
    "BUILD" => "54118205"
    "L_ERRORCODE0" => "10002"
    "L_SHORTMESSAGE0" => "Security error"
    "L_LONGMESSAGE0" => "Security header is not valid"
    "L_SEVERITYCODE0" => "Error"
  ]
}

- -編輯 - -

剛剛創建了一個新的 Sandbox Business Account 並使用了那個人的 NVP API Creds,然后它就成功了! 舊帳戶的問題可能是我編輯的電子郵件,因為這是新舊帳戶之間的唯一區別。

實時環境和測試/沙盒環境是完全獨立的,因此需要單獨的憑據。

對於 PayPal 沙盒(測試模式),您需要來自沙盒PayPal 企業帳戶的 API 用戶名、密碼和簽名,通過https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper .paypal.com%2Fdeveloper%2Faccounts%2F


10002 "Security Header is not Valid" 總是表示您的憑據無效,即用戶名/密碼/簽名有問題,或者您在沙盒模式下使用實時憑據,反之亦然

暫無
暫無

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

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