I try to build payment plugin fo Joomdonation Documents Seller, i can send order to Bank, pay and after have some problem, when order is created and sent, it has status: in_progress, after payment status changes to success, i try to change record in database with if ($status == success) but can not. here is both files, 1. i start payment
session_start();
defined('_JEXEC') or die;
class os_bog extends DSFPayment
{
public function __construct($params, $config = [])
{
parent::__construct($params, $config);
}
public function processPayment($row, $data)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://ipay.ge/opay/api/v1/oauth2/token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
CURLOPT_HTTPHEADER =>array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '. base64_encode($client_id.':'.$secret_key)),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
$token = $response ['access_token'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://ipay.ge/opay/api/v1/checkout/orders',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"intent": "CAPTURE",
"items": [
{
"amount": "'. $data['amount'].'" ,
"description": "'.$data['item_name'].'",
"product_id": "'.$data['item_name'].'"
}
],
"locale": "ka",
"redirect_url": "https://editor.ge/",
"shop_order_id": "'. $data['order_number'].'",
"show_shop_order_id_on_extract": false ,
"capture_method": "AUTOMATIC",
"purchase_units": [
{
"amount": {
"currency_code": "GEL",
"value": "'. $data['amount'].'"
}
}
]
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer' . $token ),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
$payment_hash = $response ['payment_hash'];
$order_id = $response ['order_id'];
if (isset($response['order_id'])) {
$payment_hash = $response['payment_hash'];
$order_id = $response['order_id'];
$redirect_url = $response['links'][1]['href'];
header("Location:" . $redirect_url);
}
$_SESSION['order_data'] = array(
'order_id' => $response ['order_id'],
'payment_hash' => $response ['payment_hash'],
);
return $response;
}
public function verifyPayment()
{
if ($this->validate())
{
}
}
protected function validate()
{
$this->notificationData = $_REQUEST;
return true;
}
}
i check status of payment
session_start();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://ipay.ge/opay/api/v1/oauth2/token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
CURLOPT_HTTPHEADER =>array('Content-Type: application/x-www-form-urlencoded','Authorization: Basic '. base64_encode($client_id.':'.$secret_key)),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
$token = $response ['access_token'];
$order_data = ($_SESSION['order_data']);
$order_id = $order_data['order_id'];
$payment_hash = $order_data['payment_hash'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://ipay.ge/opay/api/v1/checkout/payment/'.$order_id,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer' . $token ),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
p.s. i can not check payment inside plugin(first code), callback url is predefined by Bank and i was no able to put code inside "public function verifyPayment()"
I am far not experienced , could someone help? Thank you in advance
Related
I have a method that sends an SMS message but instead returns false. The code is used in Postman, and it works. I am using Laravel 5.8.
public function sendSMS()
{
$curl = curl_init();
curl_setopt_array(URL_API, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"number" : PHONE_NUMBER,
"message" : "Tu código de seguridad es: 289686",
"type" : 1
}',
CURLOPT_HTTPHEADER => array(
'api-key: API_KEY',
'Authorization: Bearer TOKEN_API',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
Response in Laravel
[false]
0: false
Response in Postman
{
"success": true,
"message": "Enviado",
"number": "11111111111",
"menssageId": 122585244
}
I verified that CURL is enabled on my localhost.
cURL support : enabled
cURL Information : 7.70.0
I thank you all for your time, the solution was added two parameters in the curl query.
public static function sendSMS($number,$message){
$token = json_decode(self::loginCELLVOZ(),true);
$url = env('URL_BASE') . 'sms/single';
$account = env('ACCOUNT');
$password = env('PASSWORD');
$api_key = env('API_KEY');
$phone = '551'.$number;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, //add line
CURLOPT_SSL_VERIFYHOST => false, //add line
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"number" : "'.$phone.'",
"message" : "'.$message.'",
"type" : 1
}',
CURLOPT_HTTPHEADER => array(
'api-key: '.$api_key.'',
'Authorization: Bearer '.$token['token'].'',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
NOTE:
Only is necesary this lines in localhost, not recomendly use in the server production.
I'm not able to understand how to modify this cURL into Laravel 5.8, getting {"code":"11", "message":"invalid Request found", "status":"DECLINED"} response.
Here is my cURL code which is working fine (in postman and browser):
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.hylo.biz/Api/v1.0/Payment',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"orderId":"KJDHKSGIU768",
"amount":"100",
"redirect_url":"google.com"
}',
CURLOPT_HTTPHEADER => [
'Authorization: Basic WUR1pYQ1hYY3U2Og2OGM6JJE5tWEDJhJDEwZReVE=',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Here is my laravel code:
public function process(Request $request)
{
// return $request['request'];
$client = new \GuzzleHttp\Client();
$url = "https://api.hylo.biz/Api/v1.0/Payment";
$response = $client->request('POST', $url, [
'headers' => [
'Authorization' => 'Basic WUR1pYQ1hYY3U2Og2OGM6JJE5tWEDJhJDEwZReVE=',
'Content-Type' => 'application/json'
],
'form_params' => $request['request']
]);
return $response = $response->getBody();
}
in this way it's working
public function process(Request $request)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.hylo.biz/Api/v1.0/Payment',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"orderId":"KJDHKSGIU768",
"amount":"100",
"redirect_url":"google.com"
}',
CURLOPT_HTTPHEADER => [
'Authorization: Basic WUR1pYQ1hYY3U2Og2OGM6JJE5tWEDJhJDEwZReVE=',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
}
and also I forgot to add use Illuminate\Http\Request;
I have a question about curl.
Here is the value which will be changed by the user input.
$uid = "xxxxx" //Get from system
$token = "xxxxx" //Get from system
$title = "Testing Message"; //user input
$body = "Message"; //user input
$url_on_click = "https://www.xxxxx.com"; //user input
I want to apply the value into the function but it getting error:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://bn.xxxxxx.com/wpn/wpn_send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"uid" :' . $record_uid . ',
"payload": ' . $payload . '
}',
CURLOPT_HTTPHEADER => array(
'token: ' . $record_token . ',
Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
If I change all the value to string. It's work. The follow code like :
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://bn.xxxxxx.com/wpn/wpn_send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"uid" :"xxxxxx",
"payload": {
"title": "Testing Message",
"body": "1234",
"icon":"https://xxxxx.net/xxxxx.png",
"urlOnClick":"xxxxx.com"
}}',
CURLOPT_HTTPHEADER => array(
'token: xxxxxx',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
May I know which part I did wrong? That issue really pull my hair out.
Thank you =]
Try this, post fields depend on your CURLOPT_HTTPHEADER, according to your header you need to convert it in JSON otherwise, the array type will work
$postFields = array(
'uid' => "xxxx",
'token' => "xxxx",
'title' => "xxxx",
'body' => "xxxx",
'url_on_click' => "xxxx"
);
//curl init lines
//-------
//-------
CURLOPT_POSTFIELDS => json_encode($postFields),
I am trying to perform some function based on the response I will get from Curl URL. Below is the code I have written. But the response coming is always empty. Due to which the control always goes into an else condition.
if(isset($_POST['verify_button'])){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://*******/v1/****/*********/".$_POST['********']."?MVNO=*******",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic Z*******",
"accept: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response);
if($data->resultCode == '0'){
echo '<div class="mm_success_alert">Sucess</div>';
}
else{
echo '<div class="mm_danger_alert">Fail.</div>';
}
I've set a global variable to equal an access token, and when I print_($session_id) the token is visible. What I'd like to do is pass that variable into my CURLOPT_HTTPHEADER, and have it equal to "Session" in the function get_field_data_id() below:
function get_session_id() {
global $session_id;
$curl = curl_init();
$session_url = "/auth";
curl_setopt_array($curl, array(
CURLOPT_URL => $session_url ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Accept: application/json",
"username: USER",
"password: PASS",
"authorizationkey: KEY"
),
));
$response = curl_exec($curl);
curl_close($curl);
$session_id = $response;
} add_filter( 'gform_after_submission_4', 'get_session_id' );
function get_field_data_id() {
global $session_id;
$curl = curl_init();
$file_url = "URL";
curl_setopt_array($curl, array(
CURLOPT_URL => $file_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Accept: application/json",
"Session: {$session_id}"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;}
However when I run this function, I get an error message that the session ID is invalid. What am I missing?
{"Message":"Invalid Authorization. Session ID is invalid. "}