Authentication_error

Hi, guys, I’ve got Auth error on IN-APP PAYMENTS SDK: QUICK START Step 3: Take a Payment with a cURL Command iOS Swift

Getting URL on log Xcode Log:

curl --request POST https://connect.squareup.com/v2/payments --header “Content-Type: application/json” --header “Authorization: Bearer YOUR_ACCESS_TOKEN” --header “Accept: application/json” --data ‘{“idempotency_key”: “9A13DBCF-CA59-4C45-AD22-C6A258EB5A1C”,“autocomplete”: true,“amount_money”: {“amount”: 100,“currency”: “USD”},“source_id”: "cnon:CBASEP1b-IhDYPR0KPkjzIYBjLw”}’

After the replacement of YOUR_ACCESS_TOKEN with our Sandbox Access Token (some part of token has been replaced with *) :

curl --request POST https://connect.squareup.com/v2/payments --header “Content-Type: application/json” --header “Square-Version: 2020-12-16” --header “Authorization: Bearer EAAAEFVM*****************_***********-Ejo” --header “Accept: application/json” --data ‘{“idempotency_key”: “9A13DBCF-CA59-4C45-AD22-C6A258EB5A1C”,“autocomplete”: true,“amount_money”: {“amount”: 100,“currency”: “USD”},“source_id”: “cnon:CBASEP1b-IhDYPR0KPkjzIYBjLw”}’

getting error:

{“errors”: [{“code”: “UNAUTHORIZED”,“detail”: "The Authorization http header of your request was malformed. The header value is expected to be of the format “Bearer TOKEN” (without quotation marks), where TOKEN is to be replaced with your access token (e.g. “Bearer ABC123def456GHI789jkl0”).

Please advice what is wrong. Thanks

Hi @sevriugin,

Looks like you are using the production base path URL with nonce that was created with a sandbox application Id. You will need to use https://connect.squareupsandbox.com/v2/payments for a nonce that was created in sandbox.

Thanks, I just following the instruction and using App created by Square, so maybe they need to change app code to create correct Url, will try if it works …

Looks like it works this time, thanks Bryan!
{“payment”: {“id”: “5yzQs3Kuj00a35idPF3FJjE4Gw5YY”,“created_at”: “2020-12-28T19:51:24.971Z”,“updated_at”: “2020-12-28T19:51:25.167Z”,“amount_money”: {“amount”: 100,“currency”: “USD”},“status”: “COMPLETED”,“delay_duration”: “PT168H”,“source_type”: “CARD”,“card_details”: {“status”: “CAPTURED”,“card”: {“card_brand”: “VISA”,“last_4”: “1111”,“exp_month”: 9,“exp_year”: 2023,“fingerprint”: “sq-1-WfL8e-HRHJlkhBHIc4jIoY_wuoljYZqEE2nxnll2Ve4lswA-GpxXfnJsTzBGQnbV5g”,“card_type”: “CREDIT”,“bin”: “411111”},“entry_method”: “KEYED”,“cvv_status”: “CVV_ACCEPTED”,“avs_status”: “AVS_ACCEPTED”,“statement_description”: “SQ *DEFAULT TEST ACCOUNT”},“location_id”: “LKG1811QN491Q”,“order_id”: “QMrqh381JJZNVaqmp7k4ksPIfMCZY”,“risk_evaluation”: {“created_at”: “2020-12-28T19:51:25.079Z”,“risk_level”: “NORMAL”},“total_money”: {“amount”: 100,“currency”: “USD”},“receipt_number”: “5yzQ”,“receipt_url”: “https://squareupsandbox.com/receipt/preview/5yzQs3Kuj00a35idPF3FJjE4Gw5YY","delay_action”: “CANCEL”,“delayed_until”: “2021-01-04T19:51:24.971Z”}}

That’s great that it worked. I’ll definitely share the feedback with the team. Feel free to reach out if you have any additional questions. We’re happy to help! :slightly_smiling_face:

I will because I am going to move to the next step and try to implement server but using Firebase, will copy one provided by Square for Heroku

It looks like it works also using Firebase function with min changes of code. thanks again for the help