Closed nitiapptech closed 3 years ago
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, $cardPreRegistration) {
$mangoPayApi = new \MangoPay\MangoPayApi();
$mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
$mangoPayApi->Config->ClientId = '**';
$mangoPayApi->Config->ClientPassword = '**';
$mangoPayApi->Config->TemporaryFolder = public_path('doc/');
//dd($mangoPayApi->PayIns); $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->PaymentType = 'card';
$payIn->PaymentDetails->CardType = 'CB_VISA_MASTERCARD';
$payIn->PaymentDetails->CardId = '116508117';
$payIn->CreditedUserId ='116508109';
// execution type as DIRECT
$payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect();
$payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com';
//dd($payIn); // 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>';
}
// return $this->mangopay_curl_post($api_type, $post_fields, $request_type); }
the code i am using
MangoPay\PayIn {#638 ▼ +CreditedWalletId: "116509946" +PaymentType: "CARD" +PaymentDetails: MangoPay\PayInPaymentDetailsCard {#685 ▶} +ExecutionType: "DIRECT" +ExecutionDetails: MangoPay\PayInExecutionDetailsDirect {#688 ▶} +AuthorId: "shree" +CreditedUserId: "116508109" +DebitedFunds: MangoPay\Money {#680 ▶} +CreditedFunds: MangoPay\Money {#681 ▶} +Fees: MangoPay\Money {#687 ▶} +Status: "FAILED" +ResultCode: "001023" +ResultMessage: "Author is not the card owner" +ExecutionDate: null +Type: "PAYIN" +Nature: "REGULAR" +DebitedWalletId: null +Id: "116509947" +Tag: null +CreationDate: 1629899516
Hi @nitiapptech,
I don't know if you really set $payIn->AuthorId = 'shree';
but that will not work. You need a real Id of a user that exist.
ResultMessage: "Author is not the card owner"
This mean the card you use to pay ( $payIn->PaymentDetails->CardId = '116508117';
) do not belong to the author of the payment ( +AuthorId: "shree"
)
PS: Hopefully it's not your real credential, but in case, I wouldn't expose my ClientId / Password even for the Sandbox.
Cheers, Marc.
i have got the status success now,,, but I have some queries,, i have credited the amount to user wallet but I think that it should be sandbox owner wallet but how to create that,, yes i have set earlier $payIn->AuthorId = 'shree'; this but its not working so i have to set user wallet id,, so is it right
i have credited the amount to user wallet but I think that it should be sandbox owner wallet but how to create that
I am not sure what you talking about. There are no sandbox owner wallet. There is only a Fee Wallet, that's where the fee for a transaction go but you can not make any PayIns directly to that wallet if that's what you looking for.
Pay-In has been created with status: FAILED (result code: 001023)