How to take info from a SQL Database to populate a json obj & encode object in base64 and send via post to an api using laravel

So our platform operates on Laravel/PHP/SQL/JS/Dart/Flutter/SQL/Firebase and our payment processor has an rest api in which we need to work with to send a digital invoice out for payment. Now the processor requires information (Basics Name, Email, Amount, Phone, Ipaddress, Order Number, etc.) to be included in the api call some of which won’t be available or known until after the order is placed on our system. Necessitating a spinner widget to place the order in a pending payment status to then fire the api call to collect payment after. Additionally all requests made to the api need to be converted to base64 encoding prior to being sent over the api.

According to the api documentation It says that i need to create a json object containing all the required information and encode that data using Base64 Encoding which is then sent via a put request to the api to obtain a response alongside a Payment token which will then need to be stored to be called upon later using a callback api get request. I am trying to figure out the best way to accomplish this so that our payment flow becomes:

Customer Shops Via Web / App adding items to cart
Clicks or Taps on the Confirm Order Button

Our App/Platform creates a “draft order” with a order status of pending payment & sends the necessary information to our processor to generate a digital invoice & payment token where the token is stored in our database with the rest of the order data & processor then send a text message to the customer with a link to complete DIV (Digital Identity Verification) & collect payment for the order.

Customer then follows the link & completes payment where processor indicates if the given orders payment was successful or unsuccessful in it’s system while our platform sends an additional api request using the payment tokens to get the current payment status for orders sitting in the “pending payment status” so our platform can mark the order as paid and update it’s status to processing.

I know i will invariably receive a response of why does your payment methodology need to be so complex just get processing and go and as much as we would love for that to be the case, it simply is just not possible at the moment in our industry and current political climate. Forcing us to use this type of payment methodology to be able to operate or be restricted to simply being cash only.

To be honest I have not yet attempted, as i am still trying to map out what this needs in order to work and am seeking advice on the best practical way to accomplish this using the frameworks/stack that we operate on. Admittedly i am feeling slightly intimidated by this project since management just kind of threw this in my lap after losing our backend server side developer. I am not super familiar with Laravel and am somewhat familiar with PHP however most of my background is in Flutter, Dart, Kotlin, Swift, Html, CSS, JS, React & management does not seem to know the difference and somehow expect me to make this work.

This is the stack we are currently using

  • PHP/Laravel for our Administrative Control Panel. This is where this functionality needs to be added.
  • SQL for database.
  • Flutter/Dart for Mobile app / Front End.
  • Firebase for OTP/Push Notifications etc.

Query needs to be made to database after order placement grabbing order info and placing it into a json object

Expected result should look like:


{

'ipAddress':'123.456.789.012',

'merchantId': '1234567890',

'invoicenumber': '1234',

'firstName':'Mary',

'lastName':'Jane',

'email':'[email protected]',

'currency':'USD',

'amount' : '1000',

'redirectURL':'example.com',

'apiKey': 'Rw309njyNnklbkf9Pn6YNx68494292EV'

}

Where the json object data needs to be encoded using Base64 Encoding

Where the output of that encoding should look like this:

ew0KDQonaXBBZGRyZXNzJzonMTIzLjQ1Ni43ODkuMDEyJywNCg0KJ21lcmNoYW50SWQnOiAnWENwUjQyOTInLA0KDQonZmlyc3ROYW1lJzoncmFqZXNoJywNCg0KJ2xhc3ROYW1lJzonZ29uZGFsaXlhJywNCg0KJ2VtYWlsJzonZW1haWxAZW1haWwuY29tJywNCg0KJ2N1cnJlbmN5JzonVVNEJywNCg0KJ2Ftb3VudCcgOiAnMTAwMCcsDQoNCidyZWRpcmVjdFVSTCc6J2V4YW1wbGUuY29tJywNCg0KJ2FwaUtleSc6ICdSdzMwOW5qeU5ua2xia2Y5UG42WU54Njg0OTQyOTJFVicNCg0KfQ==

Which will also then need to be stored temporarily as a string with the field name of RTPRequest

Where the encrypted string is then passed via a post request to the api endpoint

Where the response from the api endpoint will include a payment token in the body which will be needed to be added to the database table row for the order that was just sent to the api

API get callback request is then sent requesting an updated payment status and if successful updates the payment status to paid and the orders status from pending payment to processing taking the user to from the order processing spinner to their orders page.

Thoughts, suggestions, advice etc…