Mangopay / mangopay2-php-sdk

PHP SDK for MANGOPAY
https://packagist.org/packages/mangopay/php-sdk-v2
MIT License
122 stars 133 forks source link

401 - Unauthorized in production mode #369

Closed feloot closed 4 years ago

feloot commented 4 years ago

Hi,

We're trying to switch our client's site to production.

We've used the sdk demo with our own credentials MangoPay credentials.

When processing the payment, during the following call : $oMangoRegisteredCard = $oMangoPayApi->CardRegistrations->Get('825884503'); (see line 22 : https://github.com/Mangopay/mangopay2-php-sdk/blob/master/demos/paymentDirect/payment.php)

We get a 401 - Unauthorized error from MangoPay. The error is thrown in the following file : \MangoPay\Libraries\RestTool.php, in CheckResponseCode().

The card identifier (825884503 in the example) was created automatically when generating the form earlier, as per the demos.

Everything works absolutely perfectly in development mode (https://api.sandbox.mangopay.com). We only have this issue in production, although our credentials are correct.

Could you please point me to the right direction ? We've already contacted support@mangopay.com, but they told us to ask for help here.

Thanks.

Riwak commented 4 years ago

Hello @Feloot

Did you try this request on POSTMAN ? Is it work ? Can I have the user ID linked to this card registration ID (825884503)

Thanks in advance,

feloot commented 4 years ago

Hi @Riwak,

Thank you for your reply.

I'm sorry I did not try with POSTMAN, I've been exclusively working with the PHP SDK, I figured if it works in dev mode then it's probably just a configuration issue with this account somehow ?

Here's an example I've just got right now. UserId : 835425258 // = $oMangoPayApi->Users->Create($oMangoUserNatural)->Id; CardId : 835425264 // = $oMangoPayApi->CardRegistrations->Create($oMangoCardRegistration)->Id;

Sadly once again when doing this : $oMangoPayApi->CardRegistrations->Get(835425264);

I get the 401 - Unauthorized error.

Thank you so much for your guidance.

Riwak commented 4 years ago

It's weird, let's try something :

feloot commented 4 years ago

Hi,

Thank you for your reply.

I figured out the issue in the end ; in the SDK's demo examples, the API url is only configured on the form but it is not specified on the other pages, for instance : https://github.com/Mangopay/mangopay2-php-sdk/blob/master/demos/paymentDirect/payment.php

Since no url is specified, the default sandbox one is used : https://github.com/Mangopay/mangopay2-php-sdk/blob/master/MangoPay/Libraries/Configuration.php

That is why it is working in dev mode but not in production.

I hope this will help other people in the future.

Thanks and have a good day

Riwak commented 4 years ago

Oh thanks for this report ! We will check and correct this behavior !