【发布时间】:2020-05-19 03:40:15
【问题描述】:
每当使用setTestMode()方法时,都会弹出“Security header is not valid”的错误。
但如果我删除 setTestMode() 并只保留 setUsername()、setPassword() 和 setSignature() 方法,它会通过并直接重定向到 PayPal(Live Paypal)。
所以 AFAIK 问题应该在于我如何使用 setTestMode 而不是错误的 API 凭据,因为大多数“安全标头无效”错误都是关于。
我目前正在使用 Laravel 5.8 和 Omnipay/PayPal 使用 PayPal Express Checkout
这里是使用的文件
Paypal.php
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;
}
PaypalController.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"
]
}
---编辑---
刚刚创建了一个新的沙盒业务帐户并使用了该帐户的 NVP API 凭据,然后它就可以工作了!旧帐户的问题可能是我编辑的电子邮件,因为这是旧帐户和新帐户之间的唯一区别。
【问题讨论】:
标签: laravel laravel-5 paypal paypal-sandbox omnipay