Mangopay / mangopay2-php-sdk

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

Paypal Payment Creation #482

Closed ideiasfrescas closed 3 years ago

ideiasfrescas commented 3 years ago

Hello,

We are having some issues creating a payment with the SDK.

Here is what we are trying to do:

    try {
        $PayIn = new \MangoPay\PayIn();
        $PayIn->CreditedUsertId = $payin['crediteduserid'];
        $PayIn->CreditedWalletId = $payin['creditedwalletid'];
        $PayIn->AuthorId = $payin['authorid'];

        $PayIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsCard();
        $PayIn->PaymentType = \MangoPay\PayInPaymentType::PayPal;

        $PayIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect();
        $PayIn->ExecutionDetails->SecureMode = "FORCE";
        $PayIn->ExecutionDetails->SecureModeReturnURL = $payin['return_url'];
        $PayIn->ExecutionDetails->CardId = $payin['cardid'];

        $PayIn->DebitedFunds = new \MangoPay\Money();
        $PayIn->DebitedFunds->Currency = $payin['debitedfunds']['currency'];
        $PayIn->DebitedFunds->Amount = $payin['debitedfunds']['amount'];
        $PayIn->Fees = new \MangoPay\Money();
        $PayIn->Fees->Currency = $payin['fees']['currency'];
        $PayIn->Fees->Amount = $payin['fees']['amount'];
        $PayIn->ExecutionType = \MangoPay\PayInExecutionType::Web;
        $PayIn->ReturnURL = $payin['returnurl'];
        $PayIn->Tag = $payin['tag'];

        $payload = $this->api->PayIns->Create($PayIn);
    } catch(MangoPay\Libraries\ResponseException $e) {
        $payload = new stdClass();
        $payload->Error = ["code"=>$e->GetCode(),"message"=>$e->GetMessage(),"details"=>$e->GetErrorDetails()];
    } catch(MangoPay\Libraries\Exception $e) {
        $payload = new stdClass(); 
        $payload->Error = ["message"=>$e->GetMessage()];    
    }  

Without PaymentDetails we get :

array(1) { ["message"]=> string(54) "PaymentDetails is not defined or it is not object type" } 

After we add PaymentDetails(), the SDK issues:

array(1) { ["message"]=> string(56) "ExecutionDetails is not defined or it is not object type" } NULL

After we add ExecutionDetails(), the SDK issues:

array(3) { ["code"]=> int(400) ["message"]=> string(130) "Bad request. One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error." ["details"]=> object(MangoPay\Libraries\Error)#73 (5) { ["Message"]=> string(117) "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error." ["Errors"]=> object(stdClass)#76 (1) { ["CardId"]=> string(29) "The CardId field is required." } ["Id"]=> string(47) "73c1733f-0d16-41c5-b29c-a3106295d78b#1618934221" ["Date"]=> float(1618934222) ["Type"]=> string(11) "param_error" } }

What is the proper setup of ExecutionDetails and PaymentDetails in order to build a proper PayPal payment request? We have already been cleared to be part of the closed beta.

Best Regards Ideias Frescas.

fredericdelordm commented 3 years ago

Hello @ideiasfrescas,

Thank you for your report, our team is looking into it.

Have a nice day,

ideiasfrescas commented 3 years ago

Hello,

Any updates on this matter?

SoloJr commented 3 years ago

Hi @ideiasfrescas

PayIn with Paypal works as intended. I invite you to take a look here and here.

Your code has some issues. You must declare PaymentDetails as PayInPaymentDetailsPaypal() and ExecutionDetails as PayInExecutionDetailsWeb().

You may clone the repo and run the existing tests in debug mode, that may help you.

Mircea