multiparty vendor

auqid
Contributor
Contributor

I am integrating PayPal into a multi-vendor site where the payment workflow is designed to:

  1. Authorize payment when a customer requests a service.
  2. Capture payment when the seller accepts the request.
  3. Disburse payment to the seller upon service completion.

Steps and Issues:

  1. Order Creation:

    • Intent: 'authorize'
    • Custom Reference ID: Generated using a custom function.
    • Payload:
      const paypalRequest = {
      intent: 'AUTHORIZE',
      purchase_units: [
      {
      reference_id: generateCustomReferenceID(),
      amount: {
      currency_code: currentCurrency,
      value: toMoney(totalPayin),
      breakdown: {
      item_total: {
      currency_code: currentCurrency,
      value: toMoney(totalPayin),
      },
      },
      },
      payee: {
      email_address: payeePaypalEmail,
      },
      items: lineItems
      .filter(k => k.code != 'line-item/provider-commission')
      .map(item => ({
      name: findPaypalItemLabel(item),
      quantity: item.quantity,
      unit_amount: {
      currency_code: currentCurrency,
      value: toMoney(item.unitPrice.amount),
      },
      })),
      },
      ],
      };

      Order Creation Request:
      const orderResponse = await createOrder(paypalRequest);

      Payment Authorization:

      • Authorization Request:
        const [success, error] = await authorizePayment(orderID);
        const authorizationId = success?.purchase_units[0]?.payments?.authorizations[0]?.id;
        const reference_id = success?.purchase_units[0]?.reference_id;
        if (error) {
        return res.status(500).send({ message: 'Order id is not present.' });
        }

        Payment Capture (upon seller acceptance):

        • Payload:
        • const payload = {
          payment_instruction: {
          disbursement_mode: 'DELAYED',
          platform_fees: [
          {
          amount: {
          currency_code: currentCurrency,
          value: '10',
          },
          },
          ],
          },
          };
        • Capture Request:
          const captureURL = `/v2/payments/authorizations/${authorizationId}/capture`;
          const response = await axiosWithPaypal.post(captureURL, payload);
          Disbursement (upon service completion):

        • const res = await axiosWithPaypal.post('/v1/payments/referenced-payouts-items', {
          "reference_id": reference_id,
          "reference_type": "TRANSACTION_ID"
          }, {
          headers: {
          'Content-Encoding': 'gzip',
          'Prefer': 'respond-async',
          'PayPal-Request-Id': 'some-idempotency-data'
          },
          });
        • Issue: The disbursement request returns a 202 response, indicating success, but no funds are transferred from the buyer's account to the seller's account in the sandbox environment.



         

 

 

 

 

 

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.