How Can I get this done???

Omoadamo

Regular Member
Joined
Nov 22, 2016
Messages
325
Reaction score
69
Hello BHW,
Please how can I insert the below commands to my WordPress website and what do I need to remove from it as well?

Command:

https://example.com/api/data.php/?u...ber=***&amount=****&ref=12345&return_url=****

Parameters:
username: Use your Example Username
password: Your Example account password
network: MTN, 9MOBILE, GLO or AIRTEL (UPPERCASE)
phoneNumber: The beneficiary (080*** format)
amount: Use the price of the data plan e.g. 250 for Etisalat 250mb
ref: Give us your preferred reference number
return_url: Provide the url for order status.
Api Example: https://example.com/api/data.php/?u...urn_url=https://subnig.com/order_response.php
Response:
00 = Success
01 = Unsuccessful
02 = Incomplete Parameters
03 = Insufficient Balance
04 = Wrong Username or Password
05 = Invalid recipient
06 = Duplicate Order. Same network, dataplan and phone number had been ordered for in the last few minutes.
07 = Invalid Data Amount
08 = Invalid network
09 = Return Url empty
10 = Ref is empty

These parameters will be returned in the return_url:
status, beneficiary and ref
status: Can be Approved or Cancelled
beneficiary: The phone number you ordered the data plan for
ref: The reference number you provided.

Thanks in anticipation.
 
Can someone help me out in this?
 
Not entirely sure what you're trying to accomplish..

To save/remove this data you need some kind of script that will handle this and put the data/drop the data from/into the database. It's unclear if you have such script already and just trying to run an test request.

If you have such script installed, then you need to find a HTTP request builder and take the data and put it in the builder and run the request, but normally you would need a little more information to form such a request (HTTP method/Content-type (if post) etc... but if it's implemented as 'GET' HTTP request, then by calling that link directly the data should be stored (if a script exists on the site to handle the data).

You want to save the data you provided when user calls that link?

Have you implemented any 'plugins' which support this functionality or do you have a script installed?
 
Not entirely sure what you're trying to accomplish..

To save/remove this data you need some kind of script that will handle this and put the data/drop the data from/into the database. It's unclear if you have such script already and just trying to run an test request.

If you have such script installed, then you need to find a HTTP request builder and take the data and put it in the builder and run the request, but normally you would need a little more information to form such a request (HTTP method/Content-type (if post) etc... but if it's implemented as 'GET' HTTP request, then by calling that link directly the data should be stored (if a script exists on the site to handle the data).

You want to save the data you provided when user calls that link?

Have you implemented any 'plugins' which support this functionality or do you have a script installed?
@0x29a the above is an API key that a website which is into sales of mobile data gave out to site owner to integrate into their website so that, whenever someone try to buy mobile data my website, it will just trigger calling that API and credit the customer instead of redirecting them to parent website.

I hope you got my request right?
 
@0x29a I would like you to check out this website - powerhq.com.ng which I assumed uses this API key.

When I inspect the website, I could see a special plugin except paystack plugin which is used for creating payment form on the website. Though, I can't really say maybe that same plugin was use to embed that parameters key.


I want you to checkout the site powerhq.com.ng so that you can understand what I wanted. On that website, I noticed that payment was created by paystack.com form which triggered that API code of mobilenig.com for automatically sending the purchased mobile data to customers.

Thanks
 
ok, I think I understood what you're trying to do:

You have some kind of website, which needs to make an API request to website X.com with all the data, which was submitted by an user on your site, correct?

Did the website X.com provide you with the API instructions? is there any documentation regarding this request?

Based on what you posted in the original post, it looks like you simply need to make a GET request with all the arguments included to the X.com:

https://example.com/api/data.php/?username=****&password=****&network=****&phoneNumber=***&amount=****&ref=12345&return_url=****

Can you provide me with the actual URL you were given by the X.com? Is there a 'backend' you can log into (on X.com) where there's more information or at least sales report so you can test the URL?

The website you mentioned does an AJAX request, but the the actual API request is on the server side, so I cannot see what they're actually sending.

Once we figure out how to make the proper API call, you will need to add few lines of code in the wordpress (after user has submitted the data), so that wordpress sends the data to your affiliates.
 
@0x29 I'm highly grateful for you effort mate. I hope you have gotten my request right. Here is the API documentation provided by the website: api.mobilenig.com while the payment processor I'm intend to use also have a plugin couple with their documentation here: https://developers.paystack.co/docs/paystack-standard

I will be glad to hear from you.

Thanks again!
 
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!
 
Last edited:
0x29a I sincerely appreciate these efforts of yours in this regards. With regards to the above codes, it means I don't need paystack plugin again right?

I will surely feed you back on this.

Thanks once again.
 
Back
Top