Trying to implement PHP SDK -Need to check my database with PHP BEFORE I let it create the order.

JohnnyBurbank
Contributor
Contributor

I'm not a master of PHP or Paypal by any means, but I've been googling for the past 3 days and can't seem to find the right combination of code to make anything work correctly.  First, I keep seeing talk of Smart Buttons and a bunch of stuff about V1 being deprecated and I need to use V2.  Then I follow a link to an SDK that takes me here: https://github.com/paypal/Checkout-PHP-SDK.  Should I be using this because V1 will be deprecated soon?  Well, this V2 github is not super helpful because I don't have access to composer, and there are no instructions for Direct Download.  Eventually, I dig through "issues" and find some stuff about installing BraintreeHttp and somehow get that working.  But then the other half of all this is getting the Smart Buttons javascript to work properly.  First I see stuff about createOrder looking like this:
createOrder: function(data, actions) {

  return actions.order.create({

  purchase_units: [{ amount: { value: '0.01' } }] });

},

Well this doesn't work for me, because this sends the data directly to Paypal, when I need to call a PHP function to modify my database BEFORE it does that.  So I find some other version of createOrder that looks something like this:
createOrder: function() {

return fetch('/my-server/create-paypal-transaction', {

method: 'post', headers: { 'content-type': 'application/json' } })

.then(function(res) { return res.json(); })

.then(function(data) { return data.orderID; }); }

I'm assuming "/my-server/create-paypal-transaction" refers to my PHP create order code page (using the example code from the SDK github but with my proper client id and stuff).  But that doesn't work because the JSON it seems to return looks something like this (ie. not properly formatted json)...
BraintreeHttp\HttpResponse Object ( [statusCode] => 201 [result] => stdClass Object...

 

Can anyone provide the missing link to making this work?  I'm about at my wits end, and have no idea what documentation I've found is from V1 or V2 or some other archive from 10 years ago.  Is V1 really being deprecated soon?  Should I even be using Smart Buttons?  This seems far more complicated than it needs to be.  Any help is greatly appreciated.

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.