I have a project that uses Ionic and Laravel as a backend. The user uses our app based on monthly or annual subscriptions. So far I have been successful in implementing the initial charge of the subscriptions via peach payment.
So now I want every month end to charge the recurring monthly or annual subscriptions.
The idea I have is as follow:
- Run Scheduler to check subscriptions table for all monthly active users where the expiry date is month-end (31/12/2020) or is the current month.
- Generate transactions for all those users and save them to the billing table ( this is to get transaction_id to send to a payment gateway).
- Run the scheduler using the billing info where created_at is today, send each transaction to payment gateway api for processing.
- On Api response get status of each payment request and save/update the db billing table using transaction_id as primaryKey.
- Update the subscriptions table (status, new expiry date) after the billing table is update
Any help or direction with this will be appreciated. The code below is the code to use for sending a single charge request.
/**
* Monthly Subscriptions
* @param Request $request
*/
public function chargeMonthlySubscription(Request $request)
{
$curl = curl_init();
$url = "$this->url/registrations/$request->registrationId/payments";
$data = "entityId=$this->entityId" .
"&amount=$request->subscription_amount" .
"¤cy=ZAR" .
"&customer.merchantCustomerId=$request->subscription_no" .
"&customer.givenName=$request->first_name" .
"&customer.surname=$request->last_name" .
"&recurringType=$request->recurring_type" .
"&paymentType=DB";
curl_setopt_array($curl, array(
CURLOPT_URL => "$url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
$this->token,
"Content-Type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2X2veuu
via IFTTT
Characteristics of a Good Computer Program
RépondreSupprimerSubmit a form data without page refresh
Splitting MySQL Results Into Two Columns Using PHP
Dynamically Add/Delete HTML Table Rows
PHP Create Word Document from HTML
Retrieve Data From DB Without Page refresh
PHP Leap Year Program
PHP Get current directory, filename and code line
Sort Table Data in PHP and MySQL