instamojo payment gate way implementation in server - php

we are using instamojo payment gate way in our website,its working successfully in localhost but not in live server(godady) its getting error like 500(page not working). may i request you can you suggest me to solve my problem
we are using below code
<?php
$product_name=$_POST['product_name'];
$price=$_POST['product_price'];
$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
include 'src/instamojo.php';
$api = new Instamojo\Instamojo('a9979a24478f77cf21688ca8a8f46151', '025caf249cec5ad8345192a15e71602b');
try {
$response = $api->paymentRequestCreate(array(
"purpose" => $product_name,
"amount" => $price,
"buyer_name" => $name,
"phone" => $phone,
"send_email" => true,
"send_sms" => false,
"email" => $email,
"allow_repeated_payments" => false,
"redirect_url" => "http://e2dshop.com/thanq.php",
"webhook" => "http://e2dshop.com/webhook.php"
));
// print_r($response);
$pay_ulr = $response['longurl'];
echo "<script>window.location.href='$pay_ulr'</script>";
//header("Location : $pay_ulr");
exit();
}
catch (Exception $e) {
print('Error: ' . $e->getMessage());
}
?>

I know it's been very long since you asked your question, but today i faced the same issue so I am sharing my solution.
The code you pasted will work fine on localhost, but will show HTTP Error 500.
For the payment gateway to work on GoDaddy or on any live server you need to use CURL.
Please refer to the code below.
<?php
if((isset($_POST['totalAmount'])) && (!empty($_POST['totalAmount'])))
{
$amount = $_POST['totalAmount'];
$purpose = $_POST['product_name'];
$phone = $_POST['buyer_phone'];
$buyername = $_POST['buyer_name'];
$email = $_POST['buyer_email'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("X-Api-Key:yourApiKeyHere",
"X-Auth-Token:yourAuthTokenHere"));
$payload = Array(
'purpose' => $purpose,
'amount' => $amount,
'phone' => $phone,
'buyer_name' => $buyername,
'redirect_url' => 'https://www.yourwebsitehere.com/thankyou.php',
'webhook' => 'https://www.yourwebsitehere.com/webhook.php',
'send_email' => true,
'send_sms' => true,
'email' => $email,
'allow_repeated_payments' => false
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response,true);
var_dump($data);
$site=$data["payment_request"]["longurl"];
header('HTTP/1.1 301 Moved Permanently');
header('Location:'.$site);
} else {
header("Location:payment.php");
}
?>
I hope this helps you or the others who's facing the same issue currently :)
Give's a thumbs up if this helps.
Thanks.

Related

paygate payweb3 integration in php website

I am trying to integrate paygate payment gateway integration into my PHP API. I have gone through their documentation but it is not clear for me. There were three endpoints
initiate
return
query
I don't which endpoint to use. Now I am using initiate endpoint, but when testing in postman I am getting an error
ERROR=DATA_CHK error
Can anyone guide me to sort this out...
public function subscription(Request $request) {
$validator = Validator::make(
$request->all(),
array(
'subscription' => 'required|integer',
'email' => 'required|exists:users,email',
'amount' => 'required|integer',
'payment_mode' => 'required|integer',
),
array(
'exists' => 'The :attribute doesn\'t exists',
)
);
if ($validator->fails()) {
$error_messages = implode(',', $validator->messages()->all());
$response_array = array('success' => false, 'error' => Helper::get_error_message(101), 'error_code' => 101, 'error_messages'=>$error_messages);
} else {
$encryptionKey = 'AQ2Uted8BidhkIEv6oYgrqwS';
$data = array(
'PAYGATE_ID' => 1039433100014,
'REFERENCE' => 'pgtest_123456789',
'AMOUNT' => 3299,
'CURRENCY' => 'ZAR',
'RETURN_URL' => 'http://localhost/avvata/public/home',
'TRANSACTION_DATE' => date('Y-m-d H:i:s'),
'LOCALE' => 'en-za',
'COUNTRY' => 'ZAF',
'EMAIL' => $request->email,
);
$checksum = md5(implode('', $data) . $encryptionKey);
$data['CHECKSUM'] = $checksum;
$fieldsString = http_build_query($data);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, 'https://secure.paygate.co.za/payweb3/initiate.trans');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
//execute post
$result = curl_exec($ch);
echo $result;
exit();
//close connection
curl_close($ch);
}`
Thanks in advance :-)

POST Request PHP with Curl

I'm working on a wordpress project where I have to modify my theme, so I can request a JSON to an external API.
I've been searching through the internet how to do that and a lot of people use CURL.
I must do a POST request, yet I don't know how it works or how to do it.
So far I've got this code running:
$url='api.example.com/v1/property/search/';
$data_array = array(
$id_company => '123456',
$api_token => 'abcd_efgh_ijkl_mnop',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_array);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'APIKEY: 111111111111111111111',
'Content-Type: application/json'
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = curl_exec($curl);
if(!$result){die("Connection Failure");}
curl_close($curl);
echo($result);
I don't know where exactly I should put my authentication info or how does the curl methods work in PHP. Can you guys check it out and help me solve this?
There are some answers out there that would help you, such as this one.
However, WordPress actually has built-in functions to make GET and POST requests (that actually fall back to cURL I believe?) named wp_remote_get() and wp_remote_post(). Clearly in your case, you'll want to make use of wp_remote_post().
$url = 'https://api.example.com/v1/property/search/';
$data_array = array(
'id_company' => 123456,
'api_token' => 'abcde_fgh'
);
$headers = array(
'APIKEY' => 1111111111,
'Content-Type' => 'application/json'
);
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => $headers,
'body' => $data_array,
'cookies' => array()
)
);
if( is_wp_error( $response ) ){
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Success! Response:<pre>';
print_r( $response );
echo '</pre>';
}

Mailchimp Does not work on production [laravel on azure]

I deployed a small laravel app that subscribes a user to a mailchimp list.
it's very basic yet it does not work on production
NOTE: EVERYTHING is fine in Localhost env and a CONTACT FORM WORKS FINE(uses SMTP)
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=AUSERNAME
MAIL_PASSWORD=APASSWORD
MAIL_ENCRYPTION=TLS
MAILCHIMP_APIKEY=APIKEYHERE
MAILCHIMP_LIST_ID=LISTIDHERE
Controller
Newsletter::subscribe($request->email, [
'firstName' => 'test',
'lastName' => 'tessst',
'listName' => 'whishlist' ], 'subscribers');
return response()->json([
'status' => 'success',
'msg' => 'Subscribed successfully']);
laravel-newsletter Config file
<?php
return [
'apiKey' => env('MAILCHIMP_APIKEY'),
'defaultListName' => 'subscribers',
'lists' => [
'subscribers' => [
'id' => '5920168294',
],
'whishlist' => [
'id' => '8e553f3d39',
],
],
];
My i guess is that this has something to do with HTTPS (i fixed the issue by adding a file cacert.pem and referencing it in php.ini )
if this is the issue how can i fix this on azure?
And sorry there is no error output since it returns success to the ajax call.(if how can i get the response from mailchimp to check the error?)
Thanks in advance.
Well i dont know what is the issue here.
but i managed to make this work when i got rid of the package i'm using which is spatie/laravel-newsletter and used CURL instead and API V3.
$email = $request->email;
$listid = env('MAILCHIMP_LIST_ID');
$apikey = env('MAILCHIMP_APIKEY');
$server = substr($apikey, strpos($apikey, '-') + 1);
$auth = base64_encode('user:' . $apikey);
$data = array(
'apikey' => $apikey,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => 'test1',
'LNAME' => 'test2',
),
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://'. $server.'api.mailchimp.com/3.0/lists/'. $listid .'/members/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic ' . $auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
curl_close($ch);
return $result;

mailchimp api 2.0 subscribe through php?

I need an example of how to subscribe a email address to mailchimp newsletter.
Please check new api link here:
https://bitbucket.org/mailchimp/mailchimp-api-php
This is new malichimp api and I am not sure how to use it. :(
For MailChimp 2.0 API, not for 1.3.
Please somebody provide an example on how to subscribe user to mailchimp.
Thank You.
Edit1: Already tried following code, but not working:
$merge_vars = array('MM1'=>$mm1);
$MailChimp = new Mailchimp($apikey);
$result = $MailChimp->call('lists/subscribe', array(
'id' => $listid,
'email' => array('email'=>$email),
'merge_vars' => $merge_vars,
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
));
print_r($result);
But not working. Throwing following error:
Fatal error: Call to a member function call() on a non-object in subscribe.php on line 22
Referring to the documentation, this should be like so:
$merge_vars = array('MM1'=>$mm1);
$listid = 'YOURLISTID';
$MailChimp = new Mailchimp($apikey);
$result = $MailChimp->lists->subscribe($listid,
array('email'=>"contact#twittstrap.com"),
$merge_vars,
false,
true,
false,
false
);
print_r($result);
Tested and working.
this might be helpful for some, simple mailchimp subscriber API code sample with php
mailchimp subscriber API code example in PHP
Here is with Try & Catch (example for when dup emails)
header('Content-Type: application/json');
include_once 'Mailchimp.php';
$api_key = '';
$list_id = '';
$email = 'hello#email.com';
$merge_vars = array();
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);
try{
$subscriber = $Mailchimp_Lists->subscribe(
$list_id,
array('email'=>htmlentities($email)),
$merge_vars,
false,
false,
false,
false
);
echo json_encode(array('status' => !empty($subscriber['leid'])?'submitted':'error'));
} catch(Mailchimp_Error $e){
echo json_encode(array(
'status' => 'error',
'message' => $e->getMessage()
));
}
Readmore about subscribe() : https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
Subscribe through php using curl.
$apikey = 'xxxxxxxxxx'; //your apikey
$listId = 'xxxxxxxxxx'; // your list id
$endpoint = "http://yourdatacenter.api.mailchimp.com/3.0/lists/"; // find your datacenter in your apikey( xxxxxxxxxxxxxxxxxxxxxxxx-us13 <= this is your datacenter)
$auth = base64_encode( 'user:'. $apikey );
$data = array(
'apikey' => $apikey,
'email_address' => 'yourvalid_email_address',
'status' => 'subscribed',
'merge_fields' => array());
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint.$listId.'/members/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
echo "<pre>"; // Response form mailchimp
print_r(json_decode($result,true));
Here is example may it helpful for some one.
mailchimp subscriber api example

get amp; symbol using http_build_query

I am submitting some data from website1 to website2 using curl.
When I submit data via then on receiving end I get it like
Array
(
[ip] => 112.196.17.54
[amp;email] => test#test.com
[amp;user] => test123,
[amp;type] => point
[amp;password] => password
)
According to me http_build_query() producing wrong results.
"ip" field is correct rest are incorrect.
Please let me know why it happens.
curl function is given below: http_build_query($config)
function registerOnPoints($username ,$password,$email,$ip , $time )
{
$ch = curl_init("http://website2c.com/curl-handler");
curl_setopt(
$ch, CURLOPT_RETURNTRANSFER, 1);
$config = array( 'ip' => $ip,
'user' => $username,
'email' => $email,
'password'=> $password,
'time' => $time,
'type' => 'point') ;
# add curl post data
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($config));
curl_setopt($ch, CURLOPT_POST, true);
# execute
$response = curl_exec($ch);
# retreive status code
$http_status = curl_getinfo($ch , CURLINFO_HTTP_CODE);
if($http_status == '200')
{
$response = json_decode($response);
} else {
echo $http_status;
}
// Close handle
curl_close($ch);
}
If it is php version issue then, clearly speaking I have no permission to change the version of php because only the curl function is producing error rest project is completed and working as expected.
Please help me.
i guess you could try:
http_build_query($config, '', '&');
Or alternative:
$paramsArr = array();
foreach($config as $param => $value) {
$paramsArr[] = "$param=$value";
}
$joined = implode('&', $paramsArr);
//and use
curl_setopt($ch, CURLOPT_POSTFIELDS, $joined);

Categories