Paypal «Создать платежный ресурс» не работает (401 не авторизован) - PullRequest
0 голосов
/ 27 ноября 2018

Я пытаюсь реализовать PayPal.Я делаю официальный урок, и теперь я застрял на "Создание платежного ресурса"

Пример запроса:

curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {accessToken}' \
{
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [{
    "amount": {
      "total": "21.50",
      "currency": "EUR",
      "details": {
        "subtotal": "15.00",
        "tax": "2.00",
        "shipping": "2.50",
        "handling_fee": "1.00",
        "shipping_discount": "-1.00",
        "insurance": "2.00"
      }
    },

    "description": "This is the payment transaction description.",
    "custom": "This is a hidden value",
    "invoice_number": "unique_invoice_number",

    "soft_descriptor": "your order description",
    "item_list": {
      "items": [{
          "name": "Item 1",
          "description": "add description here",
          "quantity": "2",
          "price": "10.00",
          "sku": "1",
          "currency": "EUR"
        },
        {
          "name": "Voucher",
          "description": "discount on your order",
          "quantity": "1",
          "price": "-5.00",
          "sku": "vouch1",
          "currency": "EUR"
        }
      ]
    }
  }],
  "note_to_payer": "Contact us for any questions on your order.",
  "redirect_urls": {
    "return_url": "http://example.com/success",
    "cancel_url": "http://example.com/cancel"
  }
}

Я изменил - {accessToken} со своим токеном доступа:

    curl -v https://api.sandbox.paypal.com/v1/payments/payment \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer {A21AAHxasde3pBCINcYK6_VkHF2Y2M6dZIGRrvWBHKn1-0A9njg73e3KzrHAL94rVtPOOacMZzyzh-AqSagXEvGT6oY3C4UIsg}' \
    {
      "intent": "sale",
      "payer": {
        "payment_method": "paypal"
      },
      "transactions": [{
        "amount": {
          "total": "21.50",
          "currency": "EUR",
          "details": {
            "subtotal": "15.00",
            "tax": "2.00",
            "shipping": "2.50",
            "handling_fee": "1.00",
            "shipping_discount": "-1.00",
            "insurance": "2.00"
          }
        },

        "description": "This is the payment transaction description.",
        "custom": "This is a hidden value",
        "invoice_number": "unique_invoice_number",

        "soft_descriptor": "your order description",
        "item_list": {
          "items": [{
              "name": "Item 1",
              "description": "add description here",
              "quantity": "2",
              "price": "10.00",
              "sku": "1",
              "currency": "EUR"
            },
            {
              "name": "Voucher",
              "description": "discount on your order",
              "quantity": "1",
              "price": "-5.00",
              "sku": "vouch1",
              "currency": "EUR"
            }
          ]
        }
      }],
      "note_to_payer": "Contact us for any questions on your order.",
      "redirect_urls": {
        "return_url": "http://example.com/success",
        "cancel_url": "http://example.com/cancel"
      }
    }

Когда я запускаю это в консоли, я получаю

      Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 597 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / RSA_AES_256_CBC_SHA256
* 	 server certificate verification OK
* 	 server certificate status verification SKIPPED
* 	 common name: api.sandbox.paypal.com (matched)
* 	 server certificate expiration date OK
* 	 server certificate activation date OK
* 	 certificate public key: RSA
* 	 certificate version: #3
* 	 subject: C=US,ST=California,L=San Jose,O=PayPal\, Inc.,OU=PayPal Production,CN=api.sandbox.paypal.com
* 	 start date: Tue, 21 Aug 2018 00:00:00 GMT
* 	 expire date: Thu, 20 Aug 2020 12:00:00 GMT
* 	 issuer: C=US,O=DigiCert Inc,CN=DigiCert Global CA G2
* 	 compression: NULL
* ALPN, server did not agree to a protocol
> GET /v1/payments/payment HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type: application/json
> Authorization:Bearer {A21AAHxasde3pBCINcYK6_VkHF2Y2M6dZIGRrvWBHKn1-0A9njg73e3KzrHAL94rVtPOOacMZzyzh-AqSagXEvGT6oY3C4UIsg}
> 
< HTTP/1.1 401 Unauthorized
< Date: Tue, 27 Nov 2018 08:33:03 GMT
< Server: Apache
< paypal-debug-id: 3711056ae62c6
< HTTP_X_PP_AZ_LOCATOR: sandbox.slc
< Paypal-Debug-Id: 3711056ae62c6
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dapiplatformproxyserv%26TIME%3D1057095003%26HTTP_X_PP_AZ_LOCATOR%3Dsandbox.slc; Expires=Tue, 27 Nov 2018 09:03:03 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Vary: Authorization
< Content-Length: 83
< Connection: close
< Content-Type: application/json
< 

Итак, почему он не авторизует мой токен?Проблема с синтаксисом, или я что-то пропустил?

Спасибо за помощь Cheers Tim

1 Ответ

0 голосов
/ 28 ноября 2018

Попробуйте избавиться от {} вокруг значения вашего токена.Это должно быть просто:

Bearer A21AAHxasde3pBCINcYK6_VkHF2Y2M6dZIGRrvWBHKn1...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...