How to fetch order details from db to payment form or payment method script

08.08.2018 18:47
#1
chesaroalvin
Joomshopping forum user no avatar
Name: Alvin
08.08.2018
Posts: 6
Quote
How to fetch order details from db to payment form or payment method script

Hi, I am adding a new payment method and I want to fetch order details such as order number, order total alongside customer details especially the first name and their mobile number. How can I fetch these? thanks

Right now trying to declare a variable that stores the customer's mobile number using mobil_number fails.

Please help.


Joomla: Joomla! 3.6.5 Stable [ Noether ]
JoomShopping: Version 4.10.0
PHP: 5.6.30
MySQL: 5.6.39-83.1
Website Url: https://www.fitnessgym.co.ke
 
08.08.2018 20:38
#2
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25919
Quote
Aw: How to fetch order details from db to payment form or payment method script

See example
payments/pm_paypal/pm_paypal.php

 
08.08.2018 20:44
#3
chesaroalvin
Joomshopping forum user no avatar
Name: Alvin
08.08.2018
Posts: 6
Quote
Aw: How to fetch order details from db to payment form or payment method script

I have already had a look at pm_paypal, I cannot figure out which variables represent the database fetch can you help me out?

 
08.08.2018 20:48
#4
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25919
Quote
Aw: How to fetch order details from db to payment form or payment method script

$order - table order

Example

<input type='hidden' name='item_name' value='<?php print $item_name;?>'>
<input type='hidden' name='custom' value='<?php print $order->order_id?>'>
<input type='hidden' name='invoice' value='<?php print $order->order_id?>'>
<input type='hidden' name='amount' value='<?php print $order->order_total?>'>
<input type='hidden' name='currency_code' value='<?php print $order->currency_code_iso?>'>
<input type='hidden' name='address_override' value='<?php print $address_override?>'>
<input type='hidden' name='country' value='<?php print $country?>'>
<input type='hidden' name='first_name' value='<?php print $order->d_f_name?>'>
<input type='hidden' name='last_name' value='<?php print $order->d_l_name?>'>
<input type='hidden' name='address1' value='<?php print $order->d_street?>'>
<input type='hidden' name='city' value='<?php print $order->d_city?>'>
<input type='hidden' name='state' value='<?php print $order->d_state?>'>
<input type='hidden' name='zip' value='<?php print $order->d_zip?>'>
<input type='hidden' name='night_phone_b' value='<?php print $order->d_phone?>'>
<input type='hidden' name='email' value='<?php print $order->email?>'>




--------------------------
OR

for test:
print_r($order); die();

 
09.08.2018 14:41
#5
chesaroalvin
Joomshopping forum user no avatar
Name: Alvin
08.08.2018
Posts: 6
Quote
Aw: How to fetch order details from db to payment form or payment method script

Alright thanks..

However, I am still getting an error. here is my code for the payment method pm_mpesa

<?php
/**
* @version 4.7.0 05.11.2013
* @author MAXXmarketing GmbH
* @package Jshopping
* @copyright Copyright (C) 2010 webdesigner-profi.de. All rights reserved.
* @license GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');

class pm_mpesa extends PaymentRoot{

function showPaymentForm($params, $pmconfigs){
include(dirname(__FILE__)."/paymentform.php");
}

//function call in admin
function showAdminFormParams($params){
$array_params = array('business_shortcode', 'transaction_desc', 'remark');
foreach ($array_params as $key){
if (!isset($params[$key])) $params[$key] = '';
}
$orders = JSFactory::getModel('orders', 'JshoppingModel'); //admin model
include(dirname(__FILE__)."/adminparamsform.php");
}

function showEndForm($BusinessShortCode = "981852", $LipaNaMpesaPasskey = "aa766edf3ab184f104aecedd248fdf0f40426829a9c2c6a0014a9860f1752861"){

$TransactionType = "CustomerPayBillOnline";
$Amount = $order->order_total;
$PartyA = $order->d_phone;
$PartyB = "981852";
$PhoneNumber = $order->d_phone;
$CallBackURL = "https://www.fitnessgym.co.ke/zizoyesir/callback.php";
$AccountReference = "<?php print $this->order->f_name?> <?php print $this->order->l_name?>";
$TransactionDesc = "Pay";
$Remark = "Thank You";

$url = 'https://api.safaricom.co.ke/mpesa/stkpush/v1/processrequest';
$token = self::generateLiveToken();

// get url
$uri = JURI::getInstance();
$url = $uri->toString();
// get url
$instance =& JURI::getInstance();
$url = JURI::getInstance()->toString();


$timestamp = '20' . date("ymdhis");
$password = base64_encode($BusinessShortCode . $LipaNaMpesaPasskey . $timestamp);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Authorization:Bearer ' . $token));
$curl_post_data = array(
'BusinessShortCode' => $BusinessShortCode,
'Password' => $password,
'Timestamp' => $timestamp,
'TransactionType' => $TransactionType,
'Amount' => $Amount,
'PartyA' => $PartyA,
'PartyB' => $PartyB,
'PhoneNumber' => $PhoneNumber,
'CallBackURL' => $CallBackURL,
'AccountReference' => $AccountReference,
'TransactionDesc' => $TransactionType,
'Remark' => $Remark
);
$data_string = json_encode($curl_post_data);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_HEADER, false);
$curl_response = curl_exec($curl);
print_r("$curl_response");
return $curl_response;
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<form action="<?php echo JRoute::_($url); ?>" name = "paymentform" method = "post">
<input type='hidden' name='item_name' value='<?php print $item_name;?>'>
<input type='hidden' name='custom' value='<?php print $order->order_id?>'>
<input type='hidden' name='invoice' value='<?php print $order->order_id?>'>
<input type='hidden' name='amount' value='<?php print $order->order_total?>'>
<input type='hidden' name='currency_code' value='<?php print $order->currency_code_iso?>'>
<input type='hidden' name='address_override' value='<?php print $address_override?>'>
<input type='hidden' name='country' value='<?php print $country?>'>
<input type='hidden' name='first_name' value='<?php print $order->d_f_name?>'>
<input type='hidden' name='last_name' value='<?php print $order->d_l_name?>'>
<input type='hidden' name='address1' value='<?php print $order->d_street?>'>
<input type='hidden' name='city' value='<?php print $order->d_city?>'>
<input type='hidden' name='state' value='<?php print $order->d_state?>'>
<input type='hidden' name='zip' value='<?php print $order->d_zip?>'>
<input type='hidden' name='night_phone_b' value='<?php print $order->d_phone?>'>
<input type='hidden' name='email' value='<?php print $order->email?>'>
</form>
<br>
<script type="text/javascript">document.getElementById('paymentform').submit();</script>
</body>
</html>
<?php
die();
}

public static function generateLiveToken()
{
$consumer_key = "Tfn6cWvwGbqzbXmsCQ1iXXyenksHfQvZ";
$consumer_secret = "GXY2HKcYvaBAiroP";
if (!isset($consumer_key) || !isset($consumer_secret)) {
die("please declare the consumer key and consumer secret as defined in the documentation");
}
$url = 'https://api.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
$credentials = base64_encode($consumer_key . ':' . $consumer_secret);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $credentials)); //setting a custom header
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
return json_decode($curl_response)->access_token;
}
}
?>

Please help me figure out where I am going wrong.


Letzte Änderung: 09.08.2018 14:49
 
09.08.2018 16:28
#6
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25919
Quote
Aw: How to fetch order details from db to payment form or payment method script

Error?

 
09.08.2018 16:35
#7
chesaroalvin
Joomshopping forum user no avatar
Name: Alvin
08.08.2018
Posts: 6
Quote
Aw: How to fetch order details from db to payment form or payment method script

Once the user fills in their phone number in the check out without registration field, the stk push cannot read the phone number variable i.e the
$PartyA = "<?php print $order->d_phone?>";
$PhoneNumber = "<?php print $order->d_phone?>";

the response is the same when I use
$PartyA = $order->d_phone;
$PhoneNumber = $order->d_phone;

I get the curl response "Bad Request - Invalid PhoneNumer" ... meaning it does not read the customer details


Letzte Änderung: 09.08.2018 16:57
 
10.08.2018 07:49
#8
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25919
Quote
Aw: How to fetch order details from db to payment form or payment method script

Problem in format phone.

Documentation phone format?

 
10.08.2018 11:24
#9
chesaroalvin
Joomshopping forum user no avatar
Name: Alvin
08.08.2018
Posts: 6
Quote
Aw: How to fetch order details from db to payment form or payment method script

I don't think it's the format, If I place the right phone format and leave the amount as $Amount = $order->order_total it responds with "errorMessage": "Bad Request - Invalid Amount"


Letzte Änderung: 10.08.2018 13:47
 
10.08.2018 13:48
#10
chesaroalvin
Joomshopping forum user no avatar
Name: Alvin
08.08.2018
Posts: 6
Quote
Aw: How to fetch order details from db to payment form or payment method script

How do I fetch information about the order from database?
i.e using $db = JFactory::getDbo();

How do I post the information from the form to the variables $Amount, $PhoneNumber within the function?


Letzte Änderung: 10.08.2018 13:50
 
10.08.2018 21:44
#11
admin
(Support Team)
User admin
Name: Admin
05.08.2010
Posts: 25919
Quote
Aw: How to fetch order details from db to payment form or payment method script

Try
$Amount = number_format($order->order_total, 2, '.', '');


Letzte Änderung: 10.08.2018 21:45
 


Copyrights MAXXmarketing GmbH. Alle Rechte vorbehalten
Durch die Nutzung dieser Website stimme ich zu, dass Cookies zur optimalen Gestaltung der Website sowie zur Analyse der Nutzung der Website verwendet werden. Weiterführende Informationen finden Sie hier. OK, einverstanden.