简体   繁体   English

401 未经 Adyen API 授权

[英]401 Unauthorized on Adyen API

I'm trying to do a payment in my test environment in Adyen with curl but for some reason I keep getting a 401 Unauthorized response back.我正在尝试使用 curl 在 Adyen 的测试环境中进行付款,但由于某种原因,我不断收到 401 Unauthorized 响应。 I have checked the credentials of the Web Service User a dozen times but I'm sure they are correct.我已经检查了 Web 服务用户的凭据十几次,但我确定它们是正确的。 When I try the official Adyen PHP Api library ( https://github.com/Adyen/adyen-php-api-library ) I get the same results.当我尝试官方 Adyen PHP Api 库 ( https://github.com/Adyen/adyen-php-api-library ) 时,我得到了相同的结果。 I have also tried creating a new Web Service User but without results.我也尝试过创建一个新的 Web 服务用户,但没有结果。 Has anyone an idea what I'm doing wrong?有谁知道我做错了什么?

The request code:请求代码:

<?php

$request = array(
    "merchantAccount" => "MyWebsite",
    "amount" => array(
        "currency" => "EUR",
        "value" => "199"
    ),
    "reference" => "TEST-PAYMENT-" . date("Y-m-d-H:i:s"),
    "shopperIP" => "2.207.255.255",
    "shopperReference" => "YourReference",
    "billingAddress" => array(
        "street" => "Simon Carmiggeltstraat",
        "postalCode" => "1011DJ",
        "city" => "Amsterdam",
        "houseNumberOrName" => "6-60",
        "stateOrProvince" => "NH",
        "country" => "NL"
    ),
    "card" => array(
        "expiryMonth" => "08",
        "expiryYear" => "2018",
        "holderName" => "Test Card Holder",
        "number" => "4111111111111111",
        "cvc" => "737"
    ),
);

$json = json_encode($request);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://pal-test.adyen.com/pal/servlet/Payment/v25/authorise");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC  );
curl_setopt($ch, CURLOPT_USERPWD, "xxxx:xxxx");
curl_setopt($ch, CURLOPT_POST, count($request));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-type: application/json"));

// things I tried
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

$result = curl_exec($ch);

?>

The $result variable returns an empty string. $result 变量返回一个空字符串。

Response:回复:

*   Trying 91.212.42.153...
* Connected to pal-test.adyen.com (91.212.42.153) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*    subject: C=NL; ST=Noord-Holland; L=Amsterdam; O=Adyen B.V.; CN=*.adyen.com
*    start date: Jun 14 00:00:00 2016 GMT
*    expire date: Aug 13 23:59:59 2018 GMT
*    issuer: C=US; O=thawte, Inc.; CN=thawte SSL CA - G2
*    SSL certificate verify ok.
* Server auth using Basic with user 'xxxxx'
> POST /pal/servlet/Payment/v25/authorise HTTP/1.1
Host: pal-test.adyen.com
Authorization: Basic xxxxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
Accept: */*
Content-type: application/json
Content-Length: 465

* upload completely sent off: 465 out of 465 bytes
< HTTP/1.1 401 Unauthorized
< Date: Mon, 02 Apr 2018 19:58:11 GMT
< Server: Apache
< Set-Cookie: JSESSIONID=47E667BF9B585DC3BDF40F8D58493E23.test103e; Path=/pal; Secure; HttpOnly
* Authentication problem. Ignoring this.
< WWW-Authenticate: BASIC realm="Adyen PAL Service Authentication"
< Content-Length: 0
< Content-Type: text/plain; charset=UTF-8
< 
* Connection #0 to host pal-test.adyen.com left intact

401 is failed authentication. 401 是认证失败。 You are not using the correct combination of user + password.您没有使用正确的用户 + 密码组合。

You have the option to generate a password for general API usage or for POS Payments.您可以选择为一般 API 使用或 POS 支付生成密码。 Make sure that if are intending to use this API user for the general API, use the "Generate Password" and not "Generate POS Password".确保如果打算将此 API 用户用于通用 API,请使用“生成密码”而不是“生成 POS 密码”。

Oke it works now.好的,现在可以使用了。 The strange thing is that I didn't change anything.奇怪的是我没有改变任何东西。 My guess is that Adyen was having trouble on their side.我的猜测是 Adyen 在他们这边遇到了麻烦。 I'll give them a call next time when something similar happens.下次有类似情况时,我会打电话给他们。

Status: 401 with errorCode: 000 is a classic error for when the following maybe incorrect: Status: 401 with errorCode: 000 是一个典型的错误,以下内容可能不正确:

  • Use correct merchantAccount Name NOT companyAccount Name使用正确的商家帐户名称而不是公司帐户名称
  • API Key - Preferably regenerate the API Key and use the copy button in the customer area to copy it API Key - 最好重新生成API Key并使用客户区的复制按钮进行复制
  • Environment set to LIVE/TEST环境设置为 LIVE/TEST

I have one question我有一个问题

HTTP URL is working in Adyen payment getaway? HTTP URL 在 Adyen 支付之旅中有效吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM