ok, I think I see what you're trying to do here. First you need to process the payment (Paystack) and then you need to process the mobile plan (MobileNig), if the payment was successful I'm guessing.
Regardless of the order, both of these services provide you an URL to which you need to redirect your client to. I wrote a small PHP class for you, which will do this for you. It contains two functions:
Code:
getURLPaystack();
getURLMobileNig();
You will have to pass different arguments for the class based on which service your currently using, as both of these services expect different data, only thing they have in common is 'amount' and I'm not sure if it's the same currency, you will have to find that out.
MobileNig:
Code:
include( "external.php" );
$external = new External
(
array
(
'phoneNumber' => '44455566',
'amount' => '400',
'network' => 'NameOfTheNetwork',
'ref' => time()
)
);
$urlMobileNig = $external->getURLMobileNig();
echo '<a href="' . $urlMobileNig . '">Go to MobileNig</div>';
MobileNig does not make any API calls before the redirect to your site, so this function will simply construct an URL, which your client will have to click:
Code:
https://mobilenig.com/api/data.php/?username=asd&password=asd&network=NameOfTheNetwork&phoneNumber=44455566&amount=400&ref=1526591934&return_url=https%3A%2F%2Fyoursite.com%2Forder_response.php
I'm not sure about the 'ref' field, you can decide what you want there, currently if you leave it as it is, it will put a unique number in there.
Paystack
Code:
include( "external.php" );
$external = new External
(
array
(
'email' => '[email protected]',
'amount' => '500'
)
);
$urlPaystack = $external->getURLPaystack();
echo '<a href="' . $urlPaystack[ 'authorization_url' ] . '">PAY NOW!</div>';
Paystack does make a pre-API call, the class is going to take care of it and will construct an URL from the data it receives from the Paystack response for your client to click:
Code:
https://mobilenig.com/api/data.php/?username=asd&password=asd&network=NameOfTheNetwork&phoneNumber=44455566&amount=400&ref=1526591934&return_url=https%3A%2F%2Fyoursite.com%2Forder_response.php
The values I used are
hardcoded, you will probably have to use $_POST variable to read the data from some kind of form on your site and pass it to that class, depends on your sites logic really.
Code:
include( "external.php" );
$external = new External
(
array
(
'email' => $_POST[ 'email_address' ],
'amount' => $_POST[ 'amount' ]
)
);
$urlPaystack = $external->getURLPaystack();
echo '<a href="' . $urlPaystack[ 'authorization_url' ] . '">PAY NOW!</div>';
Here is the class itself, tested and working (external.php):
Code:
class External
{
private $curl;
/*
* Credentials
*/
private $keyTransaction = "sk_test_36658e3260b1d1668b563e6d8268e46ad6da3273"; // Paystack Key <-- !! UPDATE THIS !!
private $username = ""; // MobileNig Username <-- !! UPDATE THIS !!
private $password = ""; // MobileNig Password <-- !! UPDATE THIS !!
/*
* URLs
*/
private $pathTransaction = "https://api.paystack.co/transaction/initialize";
private $pathData = "https://mobilenig.com/api/data.php/?";
private $pathReturn = "https://yoursite.com/order_response.php"; // Return URL <-- !! UPDATE THIS !!
/*
* Data
*/
private $email = null;
private $amount = null;
private $phoneNumber = null;
private $network = null;
private $ref = null;
/*
* Constructor
*/
public function External( $args )
{
$this->curl = curl_init();
$this->phoneNumber = array_key_exists( 'phoneNumber', $args ) && !empty( $args[ 'phoneNumber' ] ) ? $args[ 'phoneNumber' ] : null;
$this->email = array_key_exists( 'email', $args ) && !empty( $args[ 'email' ] ) ? $args[ 'email' ] : null;
$this->amount = array_key_exists( 'amount', $args ) && !empty( $args[ 'amount' ] ) ? $args[ 'amount' ] : null;
$this->network = array_key_exists( 'network', $args ) && !empty( $args[ 'network' ] ) ? $args[ 'network' ] : null;
$this->ref = array_key_exists( 'ref', $args ) && !empty( $args[ 'ref' ] ) ? $args[ 'ref' ] : null;
}
/*
* Send transaction data to Paystack API and get the URL
*/
public function getURLPaystack()
{
if( !$this->email )
die( 'email not set' );
if( !$this->amount )
die( 'amount not set' );
curl_setopt_array
(
$this->curl,
array
(
CURLOPT_URL => $this->pathTransaction,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode
(
[
'amount'=> $this->amount,
'email' => $this->email,
]
),
CURLOPT_HTTPHEADER =>
[
"authorization: Bearer " . $this->keyTransaction,
"content-type: application/json",
"cache-control: no-cache"
]
)
);
$response = curl_exec( $this->curl );
$err = curl_error( $this->curl );
if( $err )
die('Curl returned error: ' . $err);
$tranx = json_decode( $response, true );
if( !array_key_exists( 'status', $tranx ) )
die(' API returned error: ' . $tranx[ 'message' ] );
if( !array_key_exists( 'data', $tranx ) && !array_key_exists( 'authorization_url', $tranx[ 'data' ] ) )
die( 'authorization_url missing' );
return $tranx[ 'data' ];
}
/*
* Construct URL for the MobileNig API
*/
public function getURLMobileNig()
{
if( !$this->username )
die( 'username not set' );
if( !$this->password )
die( 'password not set' );
if( !$this->network )
die( 'network not set' );
if( !$this->phoneNumber )
die( 'phoneNumber not set' );
if( !$this->amount )
die( 'amount not set' );
if( !$this->ref )
die( 'username not set' );
if( !$this->pathReturn )
die( 'username not set' );
$path = $this->pathData .
"username=" . urlencode( $this->username ) .
"&password=" . urlencode( $this->password ) .
"&network=" . urlencode( $this->network ) .
"&phoneNumber=" . urlencode( $this->phoneNumber ) .
"&amount=" . urlencode( $this->amount ) .
"&ref=" . urlencode( $this->ref ) .
"&return_url=" . urlencode( $this->pathReturn );
return $path;
}
}
Now you need to update the values I market as "
!! UPDATE THIS !!". After you have done this, you can simply save the class somewhere in the public www directory (where the wordpress is located) and include it and call it the way I described before.
After client has completed whatever tasks he was doing of ether of the sites, the site(Paystack or MobileNig) will redirect the client back to your site to the URL you have specified in the class (the $pathReturn variable). Both of the sites will pass you back data like status and bunch of other stuff, for debugging purposes you can do this:
Define the returnPath as "https://whateverisyourdomain.com/return.php" and save snippet into as 'return.php' and save it at the root of the public www directory:
Code:
<?php
print_r( $_GET );
print_r( $_POST );
That snippet will dump all the data thous sites are passing back to you. Now based on this information you can add a condition and decide what to do depending on what kind of response you get from whichever site.
I hope this makes sense to you, in worst case at least you have a working code now. If you find this helpful, please don't forget to
thumbs up my posts which you found useful

good luck!