how to integrate mazzuma payment gateway - php

please i need to connect my html form to php script form payment proccessing but i don't know how to build it.
i want php to start processing the payment when the submit button is clicked
here are the sample codes
sample payload
{
"price": 1,
"network": "mtn",
"recipient_number": "026xxxxxxx",
"sender": "024xxxxxxx",
"option": "rmta",
"apikey": "",
"orderID": ""
}
sample request
<?php
$url = 'https://client.teamcyst.com/api_call.php';
$additional_headers = array(
'Content-Type: application/json'
);
$data = array(
"price"=> 1,
"network"=> "mtn",
"recipient_number"=> "026xxxxxxx",
"sender"=> "024xxxxxxx",
"option"=> "rmta",
"apikey"=> ""
);
$data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // $data is the request payload in JSON format
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $additional_headers);
$server_output = curl_exec ($ch);
?>
sample response
{"code":1,"status":"success","id":"XXXXX"}

You just make a form with input type submit button and when you submit your form
you can access your form data with like below
if(isset($_POST['button_name']))
{
// access all form field data here
}

Related

PHP post failed cloudflare api

i'm trying to update my DNS domain record through cloudflare api using PHP Post, but the cloudflare api send response that POST method is not allowed for the api_token authentication scheme, i already tried the the api using postman and it works, but somehow in PHP the api does not work, is PHP does not support POST using token ?, some variable is stored inside env.php and i hide it because it sensitive information.
PHP code :
include("../../env.php");
//variable input by POST
$domain = $_POST['domain'];
$recordID = $_POST['recordID'];
$content = $_POST['content'];
$zoneID = $_POST['zoneID'];
//for update record
$linkRecord = "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/$recordID";
$header = array(
"Content-Type: application/json",
"Authorization: Bearer $authToken"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $linkRecord);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$bodyArray = array("type"=>"A","name"=>$domain,"content"=>$content,"proxied"=>true);
$body = json_encode($bodyArray);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$resp = curl_exec($curl);
print_r($resp);
linkRecord Variable Value:
https://api.cloudflare.com/client/v4/zones/{{my_secret_zone_id}}/dns_records/{{id_of_the_record}}
Cloudflare response of POST :
{
"success": false,
"errors": [
{
"code": 10000,
"message": "POST method not allowed for the api_token authentication scheme"
}
]
}

How to post JSON data and a request token(in the header) in cURL php

I want to send the login credentials and a pin number as a JSON data and the request token as my http header.
initially it's like this,
{
"Username":"admin",
"Password":"root123",
"PinCodeā€ : "hello321"
}
and I need to post my Request Header token as well.
and if the request is ok, I should get JSON response as follow,
{
"Title": "Mr.",
"Name": "Pushkov",
"Age": "18"
}
I'm trying to do it in cURL PHP. Below is my controller code.
I tried to save my request token to a variable and pass it in header and post username, password and pinnumber as JSON data. if the login success than user info should be displayed. but I'm struggling to move ahead from here. How can I achieve that?
public function send_data() {
$url='http://samplesite.azurewebsites.net/api/member/loginmember';
$ch = curl_init('http://localhost/main');
$data = array("Username" =>$this->input->post('un'), "Password" =>$this->input->post('pw'), "PinCode" =>$this->input->post('PinCode'));
$data_string = json_encode($data);
//echo $data_string;
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
//var_dump(json_decode($result, true));
$data2=json_decode($result, true);
$ref_id = ( ( is_array( $data2["UserCode"] ) ? implode(", ", $data2["PinCode"]) : $data2["RequestToken"] ) ); // array to string
$acc_t = $data2["RequestToken"];
$uun = $data2["UserCode"];
//echo $acc_t;
// Closing
curl_close($ch);
//print $result ;
}
In your code above, you set a URL to curl_init() and you also passed another one in CURLOPT_URL option. You can't do that in one cURL request.
If you are using OAuth 2.0 you can set the access token to CURLOPT_XOAUTH2_BEARER option.
More information, please refer to PHP manual on cURL Functions.

Sending post JSON to an api - no output

I'm working with a new API and I'm trying to understand how to correctly login and send post requests to the api.
Here are some screenshots:
Also , should this authentication be done every time a request is sent or ??(it says something about a token every 8 hours in the notes)
Here is what I did so far but I'm getting no output from that print_r(probably because I haven't authenticated as shown in the notes(Something I don't know how to do correctly):
$data_string = '{
"nameOnCard":"Johnny",
"userDetail": {
"lastName":"Smith",
"firstName":"John",
"middleInitial":"xx",
"dateOfBirth":"1975-02-28",
"addressLine1":"222333 PEACHTREE PLACE",
"city":"Winchester",
"zipCode":"GU14 7JF",
"country":"GB",
"mobileNumber":"2071234567",
"landlineNumber":"57647564234",
"email":"demouser#mailinator.com",
"currencyCode":"EUR",
"externalReferenceId":"WC34930",
"registeredFromIp":"10.10.10.10",
"acceptTermsAndConditions": true,
"acceptEsign" : true
},
"channelType": "1",
"cardProgramId": "0",
"localeTime": "2013-06-04T00:00:00.000+05:00",
"refId": "1",
"dlvAddress": {
"addressLineOne":"222333 DELIVERY PLACE",
"city":"Winchester",
"zipCode":"GU14 7JF",
"country":"GB"
}
}';
$ch = curl_init('https://wcapi.wavecrest.in/apisandbox/cards');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Developerid: xxxxxxxxxx',
'Developerpassword: xxxxxxx',
'X-Method-Override: login',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
print_r($result);
Would appreciate if anyone can help me, thanks!
EDIT: other post got inactive , editing it wouldn't have helped me.

POST JSON data to API script not parsing data

I'm trying to post json data using cURL to
an API script that submits the data to an
application. I use file_get_contents('php://input')
and the data does not get submitted to the application
But if I type in an actual email address in the "contact_email"
in the API it submits the email to the application.
Here is the cURL script first:
`
$data = '
{
"customer":
{
"first_name":"John",
"last_name":"Smith",
"email":"frednow9901#aol.com",
"phone_number":"2125555555",
"billing_address":"212 Any Street",
"billing_city":"Any City",
"billing_state":"New York",
"billing_zip":"10012",
"billing_country":"USA"
}
}
';
$ch = curl_init('http://example.com/acadd.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
`
and here is the API script it posts to:
<?php
$json_data = file_get_contents('php://input');
$cart = json_decode( $json_data );
$email = $cart->customer->email .
// Set up an object instance using our PHP API wrapper.
define("AC_URL", "https://account.api-us1.com");
define("AC_API_KEY", "api key");
require_once("./ac-api-php/includes/ac.class.php");
$ac = new AC(AC_URL, AC_API_KEY);
$post_data = array(
"contact_email" => $email , // include this or contact_id
"automation" => "9", // one or more
);
$response = $ac->api("automation/contact/add", $post_data);
echo "<pre>";
print_r($response);
echo "</pre>";?>
Take a look at this line:
$email = $cart->customer->email .
You have a period after the retrieval of the email property. This attempts to concat that with the define statement which would return 1. So sample#email.com would actually be sample#email.com1.

Sending push notification to multiple users android

i am trying yo send a push notification to multiple users, when i do it for 1 user it work perfectly the problem come when i try to send the message to multiple users.
I got the response 200 MissingRegistration (So i supposed the problem is that i dont send the ID on the correct way)
Both ids are correct because if i send the message to both individually it works
This is my code
$gcmcodes=array("one user key","the other user key");
if(isset($_GET['mensaje'])) $message = $_GET['mensaje'];
$message2 = new gcm();
$message2->sendMessageToPhone(2, $message,$gcmcodes);
function sendMessageToPhone($collapseKey, $messageText, $gcmcodes)
{
$apiKey = 'My apikey';
$headers = array('Authorization:key=' . $apiKey);
$data = array(
'registration_ids' => $gcmcodes,
'collapse_key' => $collapseKey,
'data.message' => $messageText);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo"<pre>";
var_dump($gcmcode,$response);
echo"</pre>";
if (curl_errno($ch)) {
return 'fail';
}
if ($httpCode != 200) {
return 'status code 200';
}
curl_close($ch);
return "mensaje mandado con exito";
}
The format you are using can only be used for sending a single notification at a time.
In order to send the notification to multiple registration IDs, you have to send a JSON request of the form :
{ "collapse_key": "something",
"time_to_live": 108,
"delay_while_idle": true,
"data": {
"message": "some message"
},
"registration_ids":["4", "8", "15", "16", "23", "42"]
}
Oh, and the reason you got MissingRegistration error is that when you use the plain text format, GCM expects a single Registration ID to be the value of the registration_id key (not registration_ids as you tried).

Categories