Created
October 19, 2018 21:24
-
-
Save OlabodeAbesin/524dab5d8bcdc80e72404d12a091b5f9 to your computer and use it in GitHub Desktop.
Quick Billing api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function passdata(){ | |
| $users = User::all(); | |
| foreach ($users as $key => $data) { | |
| // $data = ["Id", 'username', 'mobile_number','amount_to_bill'] | |
| $this->Bill($data, $key);//The Bill function is called on every user data in the database. | |
| } | |
| } | |
| public function Bill($data, $key){ | |
| $ch = curl_init( $url ); //The URL variable is the billing API endpoint | |
| # Setup request to send json via POST. | |
| $payload = json_encode( array( "customer"=> $data ) ); | |
| curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); | |
| curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); | |
| # Return response instead of printing. | |
| curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); | |
| # Send request. | |
| $result = curl_exec($ch); | |
| curl_multi_add_handle($mh, $ch[$key]); | |
| // execute all queries simultaneously, and continue when all are complete | |
| $running = null; | |
| do { | |
| curl_multi_exec($mh, $running); | |
| } while ($running); | |
| // curl_close($ch); | |
| // # Print response. | |
| echo "<pre>$result</pre>";//Here we expect a 200(Ok) or 500(if error) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment