0

This question has been (not fully) addressed in other posts such as PayPal Orders API schema. The API seems to indicate that multiple purchase_items can exist in an order, which act as 'contracts' between payer and sellor. The docs also seem indicate a procession like this: [purchase_items][purchase_item_request][items][item]. I have looked at the example on the API page, and altered it to include three items, and it worked, BUT it makes three charges against the credit card, where it should be just one charge for the total. So this works ... sorta.

This works for me, but 3 charges are made as opposed to one.

So I tried this to see if I could get Paypal to only make one charge:

This does not work

And, Trying to follow the documentation, I went with the following:

This does not work either

The last attempt produces an error like the others the purchase_units section is mal-formed, which is partially seen in this graphic:

This error is very similar to the error for two of the above attempts.

Now the error message includes a handy link to read about the error:

"href": "https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON"

But this just sends you, or changes to https://developer.paypal.com/api/orders/v2/ which is where I have been reading and reading.

I think, I hope I am close with the last effort above, yet I have tried more than just the two example above.

Your suggestions would be welcome. This is Orders, v2, paypal api.

I am also using laravel with https://github.com/srmklive/laravel-paypal

I tried this as well. Did not work. HELP!

This does not work as well  HELP

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • Please do not post screenshots of code, and for the PayPal REST API please use a log of the resulting JSON-formatted requests and responses whenever possible (rather than PHP formatted arrays which may or may not map correctly) – Preston PHX Feb 11 '22 at 01:22
  • Thank you for your suggestion. I will do so in the future. – Robert Bryan Davis Feb 11 '22 at 13:58

1 Answers1

1

purchase_units takes an array with no key names, i.e. purchase_units[0] must exist (and is usually the only one, unless paying multiple sellers at once)

The key name purchase_units_request is nonsense, there is none called this so it will be ignored....

The key name orders_application_context is also nonsense and will be ignored, there is no key called that either (but there is an application_context key)

Don't confuse object names in the document with the actual key name such an object goes under; look at the parent object's description for the correct key name of its members, starting with the request body and building your hierarchy out that way.

For a working example of a purchase_units with an item in JSON format (not a PHP object array, but can be converted to one), see the Integrate Checkout guide, bullet #6 in 'Add and modify the code'.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • Hi. [purchase_units_request] is part of my confusion. If you look at the following image, you will see it. https://www.dropbox.com/s/oaxt3cox5v8j8j4/2022-02-11_PurchaseRequestUnit.jpg?dl=0. It is located in the schema definitions[139]. also, [orders_application_context] also exists in the schema. it is at definitions[108] in the schema. So this is all part of my confusion. Not sure which bits to use. Thus, my post. So, I expect I need to concentrate on your 4th paragraph. which I am greatful for. It points to the [integration] section, which I have not concentrated on. – Robert Bryan Davis Feb 11 '22 at 14:22
  • As I explained above, don't confuse object names in the document with the actual key name such an object goes under. Read the parent object's description for the key name. – Preston PHX Feb 11 '22 at 15:57
  • Hi Preston, I want to thank you for your help. I finally got it. When you pointed me to the integration document, the lights went on. I am most appreciative for your help and your patience with me. Your advice has made it thru the ignorance / brain barrier. I have spent the entire week monkeying with this....so again ... thank you. – Robert Bryan Davis Feb 11 '22 at 16:00
  • Additionally, when I posted a question about IPN, someone gave me some lip about using a 20 year old technology, which was my motivation to get with a more recent method with this API. I expect I still have a lot of trenches to muddy my way thru. I ask in advance if you run into my ignorance again, I would be greatful if you show the same patience you have given me here. – Robert Bryan Davis Feb 11 '22 at 16:03
  • Nice, the Orders REST API is a much better technology to be using than the old IPN. Hopefully you'll be pairing it with a JS SDK based approval flow (instead of redirecting over to PayPal and back) https://developer.paypal.com/demo/checkout/#/pattern/server – Preston PHX Feb 11 '22 at 16:07
  • that is where I am heading. Those are the mud holes I anticipate wading thru! I hope not. I have waded in that pool with not much success. But now i can focus on that only. thanks for the link. stay well. – Robert Bryan Davis Feb 11 '22 at 16:16