Closed nitiapptech closed 3 years ago
Hello @nitiapptech,
Did you check on the MANGOPAY dashboard if your wallet has been credited ?
Hello @nitiapptech,
Did you check on the MANGOPAY dashboard if your wallet has been credited ?
not credited
what i am missing,,here is my code
public function mangopay() {
// Initialize MangoPay SDK
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
$mangoPayApi->Config->ClientId = '**';
$mangoPayApi->Config->ClientPassword = '**';
$mangoPayApi->Config->TemporaryFolder = public_path('doc/');
// Creates Natural user (owner of the payment card) $user = new MangoPay\UserNatural(); $user->FirstName = 'John'; $user->LastName = 'Smith'; $user->Email = 'email@domain.com'; $user->Birthday = time(); $user->Nationality = 'FR'; $user->CountryOfResidence = 'FR'; $user->Occupation = "programmer"; $user->IncomeRange = 3; $createdUser = $mangoPayApi->Users->Create($user);
// Register card for user $cardRegister = new \MangoPay\CardRegistration(); $cardRegister->UserId = $createdUser->Id; $cardRegister->Currency = "EUR"; $cardRegister->CardType = "CB_VISA_MASTERCARD"; //or alternatively MAESTRO or DINERS $cardPreRegistration = $mangoPayApi->CardRegistrations->Create($cardRegister);
return view('customer.payment.mangopay', compact('cardPreRegistration', 'cardRegister', 'mangoPayApi','createdUser'));
//dd($walletresult); // Suppose you want to do payin with mangopay sandbox then check this code }
public function payment($createdUser) {
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
$mangoPayApi->Config->ClientId = '**';
$mangoPayApi->Config->ClientPassword = '**';
$mangoPayApi->Config->TemporaryFolder = public_path('doc/');
$id = $createdUser;
$Wallet = new \MangoPay\Wallet();
$Wallet->Owners = array($id);
$Wallet->Description = "Demo wallet for User 1";
$Wallet->Currency = "EUR";
$walletresult = $mangoPayApi->Wallets->Create($Wallet);
$api_type = 'sandbox';
$authorId = 'shree'; // DUMMY AUTHOR ID
$CreditedWalletId = $walletresult->Id; // DUMMY WALLET ID
$returnUrl = 'http://localhost/mnl/public'; // dummy url
$country = 'FR'; // your country code
$post_fields = array(
"AuthorId" => $authorId,
"DebitedFunds" => array(
"Currency" => 'EUR',
"Amount" => 2200
),
"Fees" => array(
"Currency" => 'EUR',
"Amount" => 0
),
"CreditedWalletId" => $CreditedWalletId,
"ReturnURL" => $returnUrl,
"CardType" => "CB_VISA_MASTERCARD",
"SecureMode" => "DEFAULT",
"Culture" => $country,
"Tag" => "Postman create a payin card web",
"StatementDescriptor" => "payin"
);
$request_type = 'payins/card/web';
return $this->mangopay_curl_post($api_type, $post_fields, $request_type);
}
//curl method for all the mangopay apis calls public function mangopay_curl_post($api_type, $post_fields, $request_type) { $post_fields = json_encode($post_fields); $curl = curl_init();
if ($api_type == 'sandbox') {
$server_name = "https://api.sandbox.mangopay.com"; // sandbox url
} else {
$server_name = "https://api.mangopay.com";
}
$version = "v2.01";
$client_id = "shree";
$password = "ducp0Oinf5cUaAR3FMOXaPA6DV7BEBvf40ZOdpPGFQyJ8hMuh4";
$basic = base64_encode($client_id . ":" . $password);
curl_setopt_array($curl, array(
CURLOPT_URL => "$server_name/$version/$client_id/$request_type",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_fields,
CURLOPT_HTTPHEADER => array(
"authorization: Basic $basic",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
echo '<pre>';
print_r($response); // here you can get success response of api
curl_close($curl);
}
@nitiapptech The code you are sharing is not related to the SDK.
Please consult the tests in the SDK to have Payin examples.
can i use the php sdk code in my laravel also??
also when i am trying to clone this project and use it : https://github.com/Mangopay/cardregistration-js-kit
I am getting error : Fatal error: Uncaught Error: Class 'Psr\Log\NullLogger' not found in C:\xampp\htdocs\mangopay-card\demo\mangopay2-php-sdk\MangoPay\MangoPayApi.php:224 Stack trace: #0 C:\xampp\htdocs\mangopay-card\demo\index.php(8): MangoPay\MangoPayApi->__construct() #1 {main} thrown in C:\xampp\htdocs\mangopay-card\demo\mangopay2-php-sdk\MangoPay\MangoPayApi.php on line 224
but when trying to access PHP sdk alone then it working fine
You can use the PHP SDK in Laravel without issue.
I would recommend to adapt the JS registration kit to your need but not using it directly.
public function mangopay() {
// Initialize MangoPay SDK
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
$mangoPayApi->Config->ClientId = 'shree';
$mangoPayApi->Config->ClientPassword = 'ducp0Oinf5cUaAR3FMOXaPA6DV7BEBvf40ZOdpPGFQyJ8hMuh4';
$mangoPayApi->Config->TemporaryFolder = public_path('doc/');
// Creates Natural user (owner of the payment card) $user = new MangoPay\UserNatural(); $user->FirstName = 'John'; $user->LastName = 'Smith'; $user->Email = 'email@domain.com'; $user->Birthday = time(); $user->Nationality = 'FR'; $user->CountryOfResidence = 'FR'; $user->Occupation = "programmer"; $user->IncomeRange = 3; $createdUser = $mangoPayApi->Users->Create($user);
// Register card for user $cardRegister = new \MangoPay\CardRegistration(); $cardRegister->UserId = $createdUser->Id; $cardRegister->Currency = "EUR"; $cardRegister->CardType = "CB_VISA_MASTERCARD"; //or alternatively MAESTRO or DINERS $cardPreRegistration = $mangoPayApi->CardRegistrations->Create($cardRegister);
// dd($cardPreRegistration->Id); return view('customer.payment.mangopay', compact('cardPreRegistration', 'cardRegister', 'mangoPayApi', 'createdUser'));
//dd($walletresult); // Suppose you want to do payin with mangopay sandbox then check this code }
public function payment($createdUser, $cardPreRegistration) {
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
$mangoPayApi->Config->ClientId = 'shree';
$mangoPayApi->Config->ClientPassword = 'ducp0Oinf5cUaAR3FMOXaPA6DV7BEBvf40ZOdpPGFQyJ8hMuh4';
$mangoPayApi->Config->TemporaryFolder = public_path('doc/');
$api_type = 'sandbox';
$authorId = 'shree'; // DUMMY AUTHOR ID
$Wallet = new \MangoPay\Wallet();
$Wallet->Owners = array($createdUser);
$Wallet->Description = "Demo wallet for owner";
$Wallet->Currency = "EUR";
$walletresult = $mangoPayApi->Wallets->Create($Wallet);
try {
$payIn = new \MangoPay\PayIn();
$payIn->CreditedWalletId = $walletresult->Id;
$payIn->AuthorId = 'shree';
$payIn->DebitedFunds = new \MangoPay\Money();
$payIn->DebitedFunds->Amount = '2000';
$payIn->DebitedFunds->Currency = 'EUR';
$payIn->Fees = new \MangoPay\Money();
$payIn->Fees->Amount = 0;
$payIn->Fees->Currency = 'EUR';
// payment type as CARD
$payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsCard();
$payIn->PaymentDetails->CardType = 'CB_VISA_MASTERCARD';
$payIn->PaymentDetails->CardId = $cardPreRegistration;
// execution type as DIRECT
$payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect();
$payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com';
// create Pay-In
$createdPayIn = $mangoPayApi->PayIns->Create($payIn);
//dd($createdPayIn); //die(); // if created Pay-in object has status SUCCEEDED it's mean that all is fine if ($createdPayIn->Status == \MangoPay\PayInStatus::Succeeded) { print '
print '<div style="color: red;">'
. '\MangoPay\ResponseException: Code: '
. $e->getCode() . '<br/>Message: ' . $e->getMessage()
. '<br/><br/>Details: ';
print_r($e->GetErrorDetails())
. '</div>';
}
now i am using php sdk code ,,, still getting error ,,, cant able to create pay in
\MangoPay\ResponseException: Code: 400 Message: Bad request. One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error.
Details: MangoPay\Libraries\Error Object ( [Message] => One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error. [Errors] => stdClass Object ( [CardId] => The value 116504987 is not valid ) [Id] => 4dd8a571-32bf-42ef-af7d-ddb9f72dbf6d#1629897462 [Date] => 1629897463 [Type] => param_error ) the response I am getting
Pay-In has been created with status: FAILED (result code: 001023)
https://xtraordinarycodes.blogspot.com/2020/10/mangopay-php-curl-method.html i am using this code and getting response like this: {"Id":"116472735","Tag":"Postman create a payin card web","CreationDate":1629881484,"AuthorId":"shree","CreditedUserId":"116472679","DebitedFunds":{"Currency":"EUR","Amount":2200},"CreditedFunds":{"Currency":"EUR","Amount":2200},"Fees":{"Currency":"EUR","Amount":0},"Status":"CREATED","ResultCode":null,"ResultMessage":null,"ExecutionDate":null,"Type":"PAYIN","Nature":"REGULAR","CreditedWalletId":"116472733","DebitedWalletId":null,"PaymentType":"CARD","ExecutionType":"WEB","RedirectURL":"https://api.sandbox.mangopay.com/Content/PaylineTemplateWidget?rp=49274a44a1194fbf9a3546bae4b5ed53&transactionId=116472735&token=1JavA8R1IiLIlvk425031629881484299","ReturnURL":"http://localhost/mnl/public?transactionId=116472735","TemplateURL":"https://api.sandbox.mangopay.com/Content/PaylineTemplateWidget?rp=49274a44a1194fbf9a3546bae4b5ed53&transactionId=116472735","CardType":"CB_VISA_MASTERCARD","Culture":"FR","SecureMode":"DEFAULT","Billing":{"FirstName":"shree","LastName":"shree","Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null}},"Shipping":{"FirstName":"shree","LastName":"shree","Address":{"AddressLine1":null,"AddressLine2":null,"City":null,"Region":null,"PostalCode":null,"Country":null}},"StatementDescriptor":"payin"}
but payment not done.