Search code examples
laravelpaypallaravel-8payment-gateway

How to Set Up Multiparty Payments (Onboard Sellers)


I am Trying To Implement Paypal Multiparty payment so i can connect seller and Buyers and then i take x% of fee from them for using the platform eg. Fiverr,Upwork,Freelancer, so first the seller connect his account and then they can sell services and accept payment through paypal but i dont know how to connect There Paypal account to My app

I am using laravel 9 with srmklive/laravel-paypal package

This is my Code

Route::get('https://api-m.sandbox.paypal.com/v2/customer/partner-referrals', function () {
      $provider = new PayPalClient;
      $provider->setApiCredentials(config('paypal'));
      $paypalToken = $provider->getAccessToken();
      
      $partner = $provider->createPartnerReferral([
        "operations" => [
          [
            "operation" => "API_INTEGRATION",
            "api_integration_preference" => [
              "rest_api_integration" => [
                "integration_method" => "PAYPAL",
                "integration_type" => "FIRST_PARTY",
                "first_party_details" => [
                  "features" => [
                    "PAYMENT",
                    "REFUND"
                  ],
                  "seller_nonce" => uniqid()
                ]
              ]
            ]
          ]
        ],
        "products" => [
          "EXPRESS_CHECKOUT"
        ],
        "legal_consents" => [
          [
            "type" => "SHARE_DATA_CONSENT",
            "granted" => true
          ]
        ]
      ]);
      dd($partner);
    })

this is the out put

^ array:2 [▼
  "type" => "error"
  "message" => "{"operations":[{"operation":"API_INTEGRATION","api_integration_preference":{"rest_api_integration":{"integration_method":"PAYPAL","integration_type":"FIRST_PARTY","first_party_details":{"features":["PAYMENT","REFUND"],"seller_nonce":"623a1fcec9be3"}}}}],"products":["EXPRESS_CHECKOUT"],"legal_consents":[{"type":"SHARE_DATA_CONSENT","granted":true}]} {"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"f64fe0ec63213","information_link":"","details":[{"issue":"INVALID_STRING_LENGTH","description":"The length of a field value should not be shorter than 44 characters.","field":"/operations/0/api_integration_preference/rest_api_integration/first_party_details/seller_nonce","location":"body"}],"links":[]} ◀"
]

Thank in Advance

Route::get('https://api-m.sandbox.paypal.com/v2/customer/partner-referrals', function () {
      $provider = new PayPalClient;
      $provider->setApiCredentials(config('paypal'));
      $paypalToken = $provider->getAccessToken();
      
      $partner = $provider->createPartnerReferral([
        "operations" => [
          [
            "operation" => "API_INTEGRATION",
            "api_integration_preference" => [
              "rest_api_integration" => [
                "integration_method" => "PAYPAL",
                "integration_type" => "FIRST_PARTY",
                "first_party_details" => [
                  "features" => [
                    "PAYMENT",
                    "REFUND"
                  ],
                  "seller_nonce" => uniqid()
                ]
              ]
            ]
          ]
        ],
        "products" => [
          "EXPRESS_CHECKOUT"
        ],
        "legal_consents" => [
          [
            "type" => "SHARE_DATA_CONSENT",
            "granted" => true
          ]
        ]
      ]);
      dd($partner);
    })

this is the out put

^ array:2 [▼
  "type" => "error"
  "message" => "{"operations":[{"operation":"API_INTEGRATION","api_integration_preference":{"rest_api_integration":{"integration_method":"PAYPAL","integration_type":"FIRST_PARTY","first_party_details":{"features":["PAYMENT","REFUND"],"seller_nonce":"623a1fcec9be3"}}}}],"products":["EXPRESS_CHECKOUT"],"legal_consents":[{"type":"SHARE_DATA_CONSENT","granted":true}]} {"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"f64fe0ec63213","information_link":"","details":[{"issue":"INVALID_STRING_LENGTH","description":"The length of a field value should not be shorter than 44 characters.","field":"/operations/0/api_integration_preference/rest_api_integration/first_party_details/seller_nonce","location":"body"}],"links":[]} ◀"
]

Solution

  • After some search, I found out the problem was that my seller_nonce field was lowered than 44 characters, so make sure your seller_nounce is more than 44 characters. Also, make sure you have checked the box On Board After Payment

    seller_nonce => uniqid(Str::random(40), true)