I'm trying to register a credit card with MangoPay.
On my service file, I've created a public function to register the card, using the package mangopay/php-sdk-v2
.
// ApiUser.php
public function Registration($UserId)
{
$CardRegistration = new \MangoPay\CardRegistration();
$CardRegistration->UserId = $UserId;
$CardRegistration->Currency = "EUR";
$CardRegistration->CardType = "CB_VISA_MASTERCARD";
$Result = $this->mangoPayApi->CardRegistrations->Create($CardRegistration);
$this->registration = $Result;
return $Result;
}
Its result will be an object, within three main keys: AccessKey
, PreRegistrationData
and CardRegistrationURL
.
{
[...]
"AccessKey": "1X0m87dmM2LiwFgxPLBJ",
"PreregistrationData": "YkgVxL1yNY4ZOfKtqEew_ZzBSGg0ie3ghohlFhb-37oidM_c0HMmR9H0WvKWb8pa2ddFLVXdicolcUIkv_kKEA",
"CardRegistrationURL": "https://homologation-webpayment.payline.com/webpayment/getToken",
[...]
}
While trying with PostMan, I just have to take the URL in the CardRegistrationURL
and, in its body
, add: data
with the PreRegistrationData
, accessKeyRef
with AccessKey
and cardNumber
, cardExpirationDate
and cardCvx
(the Content-Type
is x-www-urlencoded
)
Once clicked on the Send
button, its response will be a long string that start by data=
.
With that string, I can finally update the CardRegistration
object and give the user on MangoPay the credit card.
The problem is that while coding, I can't find a way to get the response of the CardRegistrationURL
.
I've tried to do a POST
while using the http-client
package, but the response given is an object. I've checked if it was present within the object, but it was not.
I've also tried to check this: https://github.com/Mangopay/mangopay2-php-sdk/blob/master/demos/paymentDirect/payment.php and tried to emulate it, but without success.
Warning: You don't have to collect card details on your server side, you have to create an HTML form like this
<form action="CardRegistrationURL here">
// inputs for cardNumber, expiration date ...
// You can add an input to redirect your user after card registration, ex:
// <input name="returnUrl" value="https://youwebsite.com">
</form>
You user will be redirected to MangoPay server then come back to your website. When the user comes back to your website use the request data to update card registration and do related things.
The documentation is not very clear, don't hesitate to ask MangoPay support.