Search code examples
paypalpaypal-rest-sdkexpress-checkout

Migrating from API V1 to V2: How to getPaymentInstuctions after capture order?


I'm trying to migrate from API V1 to V2 in PHP. In V1, you could use this code to get further payment-instructions after executing a payment:

try {
    $execution = new Paypal\Api\PaymentExecution();
    $execution->setPayerId($sPayerId);
    $payment = \Paypal\Api\Payment::get($sPaymentId, getApiContext());
    $payment->execute($execution, getApiContext());

    $payment = \Paypal\Api\Payment::get($sPaymentId, getApiContext()); // re-fetch payment with payment-instructions
    if ($payment->getPaymentInstruction())
    {   $sBankName = $payment->getPaymentInstruction()->recipient_banking_instruction->bank_name;
        $sBandAccountNumber = $payment->getPaymentInstruction()->recipient_banking_instruction->international_bank_account_number;
    ...
    }
}
catch(PayPal\Exception\PayPalConnectionException $ex) {
...
}

It's important for us to display the payment-instructions to our customer: If they use the "pay later"/"pay via invoice"-feature, they need to know to which bank and account to transfer the money to.

In API V2, you use this code to capture an authorized order:

$request = new PayPalCheckoutSdk\Orders\OrdersCaptureRequest($sOrderId);
try {   
    $response  = getClient()->execute($request);
}
catch(PayPalHttp\HttpException $exception) {
    ....
}

So what are the next steps to get the payment-instructions now?


Solution

  • The field was not documented for the v1/payments API.

    For v2/checkout/orders , a payment_instruction field is documented as an order creation request field (within purchase_units) and response field.

    A similar field exists when capturing an authorization.


    For Pay Upon Invoice, there is a processing_instruction field.

    In all these cases, the fields do not contain information regarding "which bank and account to transfer the money to" or similar.

    However, for PUI there is a response field payment_source.pay_upon_invoice.deposit_bank_details . Perhaps this is what you are looking for.

    {
      "id": "5O190127TN364715T",
      "intent": "CAPTURE",
      "status": "COMPLETED",
      "processing_instruction": "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",
      "payment_source": {
        "pay_upon_invoice": {
          "birth_date": "1990-01-01",
          "name": {
            "given_name": "John",
            "surname": "Doe"
          },
          "email": "[email protected]",
          "phone": {
            "national_number": "6912345678",
            "country_code": "49"
          },
          "billing_address": {
            "address_line_1": "Schönhauser Allee 84",
            "admin_area_2": "Berlin",
            "postal_code": "10439",
            "country_code": "DE"
          },
          "payment_reference": "b8a1525dlYzu6Mn62umI",
          "deposit_bank_details": {
            "bic": "DEUTDEFFXXX",
            "bank_name": "Deutsche Bank",
            "iban": "DE89370400440532013000",
            "account_holder_name": "Paypal - Ratepay GmbH - Test Bank Account"
          }
        }
      },
      "purchase_units": [
        ....
      ],
      "links": [
        ....
      ]
    }