0

I try to manage a subsbription to several service purchase with PayPal

First step: Crate a Checkout Order with a purchase_units each service subscriptio.

Second step: In the return url (after the Authorize Payment) I capture the payment for the order.

Third step: watch the webhook, and I received this events:

  1. BILLING.PLAN.CREATED (mark my payment as Waiting)
  2. CHECKOUT.ORDER.APPROVED (activation of the purchase services)
  3. PAYMENT.CAPTURE.COMPLETED (creation of Invoice, send Invoice, mark Invoice as pai)

My code is

$invoiceNumber = $this->client->invoice->nextNumber();
$invoiceNumber = $invoiceNumber->invoice_number;
...
$invoiceArray = [...];
$response = $this->client->invoice->createDraft($invoice);
// My response is not like documentation
$invoiceId = ltrim(strrchr($response->href, '/'), '/');
$this->client->invoice->send($invoiceId, [
    'send_to_invoicer' => false,
    'send_to_recipient' => true,
]);
...
$this->client->invoice->recordPayment($invoiceId, $recordBody);

The real problem is how build the $recordBody

I try in several mode, but every attempt fail

Following the API Documentation my $recordBody must be like this

$recordBody = [
    'amount' => [
        'currency_code' => 'EUR',
        'value' => number_format($total, 2, '.', '')
    ],
    'method' => 'PAYPAL',
    'payment_id' => ???,
];

but how use for the payment_id parameter? I try to use EVERY ID received but the only message I receive is

{
  "name":"RESOURCE_NOT_FOUND",
  "message":"The specified resource does not exist.",
  "debug_id":"b52ee464c946e",
  "details":[],
  "links":[
    {
      "href":"https://developer.paypal.com/docs/api/invoicing/#errors",
      "method":"GET"
    }
  ]
}

searching I found this alternative $recordBody (I copy the source)

$recordBody = [
  "payment_date" => "2023-06-07T07:58:25Z",
  "transaction_id" => "2KU35265BX277451G"
]

but the PayPal error is

{
  "name":"INVALID_REQUEST",
  "message":"Request is not well-formed, syntactically incorrect, or violates schema.",
  "debug_id":"116d3f3bcc4f3",
  "details":[
    {
      "field":"/method",
      "location":"body",
      "issue":"MISSING_REQUIRED_PARAMETER",
      "description":"Payment method is missing. Please provide a valid payment method."
    }
  ],
  "links":[
    {
      "href":"https://developer.paypal.com/docs/api/invoicing/#errors",
      "method":"GET"
    }
  ]
}

I SOLVE! I Solve this problem 2 minutes after send this post!

The API documentation of invoicing/invoice/{id}/record-payment IS WRONG!!! 3 days of attempts!

This is the correct $recordBody

$recordBody = [
            "payment_date" => date("Y-m-d"),
            'amount' => [
                'currency_code' => 'EUR',
                'value' => number_format($total, 2, '.', '')
            ],
            'method' => 'PAYPAL',
            'transaction_id' => $event['resource']['id'], // this paramete is not documented

// 'payment_id' => $event['resource']['id'], // this is the parameter in the documentation ]

Ephraim
  • 260
  • 1
  • 6
  • 15
  • I solve after 2 minute I send this post! The API PayPal documentation is WRONG! – Ephraim Jun 09 '23 at 14:43
  • $recordBody = [ "payment_date" => date("Y-m-d"), 'amount' => [ 'currency_code' => 'EUR', 'value' => number_format($total, 2, '.', '') ], 'method' => 'PAYPAL', 'transaction_id' => $event['resource']['id'], // this paramete is not documented // 'payment_id' => $event['resource']['id'], // this is the parameter in the documentation ] – Ephraim Jun 09 '23 at 14:46

0 Answers0