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