Credit card detail in Magento - php

How can I get the credit card detail in Magento from OnepageController.php?
I have retrieved all the other information like billing information, shipping information and user details. I am using the following to get the card detail but it returns blank:
$lastQuoteId = $session->getLastQuoteId();
$lastOrderId = $session->getLastOrderId();
$order = Mage::getModel('sales/order')->load($lastOrderId);
$card_exp_month = $order->getCcExpMonth($lastOrderId);///(Nahi AAya)
$card_exp_year = $order->getCcExpYear($lastOrderId);///(Nahi AAya)
When I print $card_exp_month and $card_exp_year, both are blank. Is there another way by which I can determine the credit card detail? I'm looking for CC number, expiry year and expiry month.

Instead of $order->getCcExpMonth($lastOrderId) try $order->getPayment()->getCcExpMonth($lastOrderId).
Use print_r($order->getPayment()->debug()) to see what other values are available, or view the sales_flat_order_payment table to see some more examples.

CC Last 4: $order->getPayment()->getCcLast4()
Exp Info:
$order->getPayment()->getCcExpMonth()
$order->getPayment()->getCcExpYear()

I got the card details in phtml file like following way.
$lastOrderId = Mage::getSingleton('checkout/session')
->getLastRealOrderId();
$order=Mage::getModel('sales/order')->loadByIncrementID($lastOrderId);
$payarry=$order->getPayment()->debug();
foreach($payarry as $key => $cardinfo)
{
echo $key;
echo $cardinfo;
}

Also
$quote = Mage::getSingleton('checkout/session')->getQuote(); // or load by id
$order = $quote->getOrder();
$payment = $quote->getPayment();
$instance = $payment->getMethodInstance();
$ccNumber = $instance->getInfoInstance()->getCcNumber();
$ccExpMonth = $instance->getInfoInstance()->getCcExpMonth();
and so on for CcCid, CcOwner, etc...

<?php
require_once("app/Mage.php");
$app = Mage::app('');
$salesModel=Mage::getModel("sales/order");
$salesCollection = $salesModel->getCollection();
foreach($salesCollection as $order)
{
$orderId= $order->getIncrementId(); echo "<br/>";
echo $orderId;
$payarry=$order->getPayment()->debug();
foreach($payarry as $key => $cardinfo)
{
echo"<pre>"; print_r($payarry);
//echo $key; echo "<br/>";
//echo $cardinfo; echo "<br/>";
}
}
?>

Related

php class function call single quote issue

I am wiring up the Authorize.net API for a web site and I have created a cart system where all is well so far. My issue is with the way I am using a parameter in one of the class function calls. It will only work if I use single quotes surrounding my string. I cannot use a variable at all it throws an error which is the reason I am here asking this question. For example:
$lineItem->setDescription('SOME TEXT GOES HERE'); // works perfectly
$foo = 'SOME TEXT GOES HERE';
$lineItem->setDescription($foo); // fails
$lineItem->setDescription("$foo"); // fails
// I tried all kinds of ways like:
$foo = "SOME TEXT GOES HERE"; // double quotes
$lineItem->setDescription($foo); // fails
// I tried this too and this works but In my case I am within a loop
define("FOO", $foo);
$lineItem->setDescription(FOO); // works but I need to loop all the items
// I tried this
$foo = json_encode($foo);
$lineItem->setDescription($foo); // fails?
// It seems like this would work but I know this is not realistic.
$lineItem->setDescription('$foo'); // this is just for illustrative purposes
So what am I doing wrong? If I could print a variable in single quotes it would seem to work but PHP doesn't work like that. Can anyone give me another way to get this to work?
Thanks in advance.
Let me show the full function so everyone can see whats happening...
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
function AuthorizeNet(){
require 'assets/authorizenet/vendor/autoload.php';
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName($GLOBALS['authorizenet_api']);
$merchantAuthentication->setTransactionKey($GLOBALS['authorizenet_tx']);
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2038-12");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Create the Bill To info
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
$billto->setPhoneNumber("310-867-5309");
$total = 0;
$tax=0;
$shipping=0;
$items_subtotal = 0;
$discount_total = 0;
$lineItem_Array = array();
$i=0;
// Create the items
foreach($_SESSION['ms_cart'] as $cart_item){
$desc = array();
if(!empty($cart_item["size"])){
$desc[] = "Size: " . $cart_item["size"];
}
if(!empty($cart_item["color"])){
$desc[] = "Color: " . $cart_item["color"];
}
$description = implode(", ", $desc);
if(!empty($cart_item["discount_total"])){
$discount_total = $discount_total+round($cart_item["discount_total"],2);
}
$name = $cart_item["name"];
$desc = $description;
$quantity = $cart_item["qty"];
$price = $cart_item["price"];
$sku = $cart_item["uiid"];
$items_subtotal = ($price*$quantity)+$items_subtotal;
$lineItem = new AnetAPI\LineItemType();
$lineItem->setItemId($sku);
$lineItem->setName($name); // <-- this is my issue
$lineItem->setDescription($desc); // <-- also here
$lineItem->setQuantity(1);
$lineItem->setUnitPrice(1);
$lineItem->setTaxable(0); // 1 Yes 0 for no
$lineItem_Array[$i] = $lineItem;
$i++;
}
$subtotal = round($items_subtotal, 2);
if(!empty($_SESSION['ms_cart_tax'])){
$tax = number_format(round($_SESSION['ms_cart_tax'], 2), 2, '.', '');
}
if(!empty($_SESSION['ms_ship_rate'])){
$shipping = round($_SESSION['ms_ship_rate'], 2);
}
$total = ($subtotal+$tax+$shipping)-$discount_total;
$total = round($total,2);
// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction");
$transactionRequestType->setBillTo($billto);
$transactionRequestType->setLineItems($lineItem_Array);
$transactionRequestType->setPayment($paymentOne);
$total=4; // there are 4 items in my cart loop for now I have hard coded the 4
$transactionRequestType->setAmount($total);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse($GLOBALS['authorizenet_env']);
if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )
{
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
}
else
{
echo "Charge Credit Card ERROR : Invalid response\n";
}
}
else
{
echo "Charge Credit card Null response returned";
}
}
This was not a good solution for me. I ended up removing the php-sdk and creating my own function to call Authorize.net's API. With some simple PHP JSON and cURL. I was up and running in an hour. Sometimes fussing around with API's can make you spend more time than just writing from scratch. I would like to thank everyone that took the time to take look and provide feedback.

How to combine functions to get several types of information

I use the Youtube Api to get information about a single video. When I do a request with an url like:
https://www.googleapis.com/youtube/v3/videos?part=status,snippet,contentdetails&id=$videoID&key=$apikey
I get all the info which I need. The problem is that I can not find a way to combine the functions that I have to get the information in one go.
What I got so far:
function getDescription($videoID){
$apikey = "<MYKEY>";
$desc = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$videoID&key=$apikey");
$description =json_decode($desc, true);
foreach ($description['items'] as $videodesc)
{
$description= $videodesc['snippet']['description'];
}
return $description;
}
function getPublishedAt($videoID){
$apikey = "<MYKEY>";
$pub = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$videoID&key=$apikey");
$publish =json_decode($pub, true);
foreach ($publish['items'] as $published)
{
$publish= $published['snippet']['publishedAt'];
}
$publish = new DateTime($publish);
$publish = $publish->format('Y-m-d H:i:s');
return $publish;
}
echo "<br>Description: ";
echo getDescription("<VIDEO-ID>");
echo "<br>PublishedAt: ";
echo getPublishedAt("<VIDEO-ID>");
So, this code works, but I like to do ONE request to the api (using multiple parts in the url) and get the information.
Does anyone has a clue how to do this using one function only?
Ok, I found the answer myself:
$videoinfo = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=<video-id>&part=snippet,status,contentDetails,statistics&part=statistics&key=<api-key>");
$videoinfo =json_decode($videoinfo, true);
foreach ($videoinfo['items'] as $embed)
{
$emb= $embed['status']['embeddable'];
$license= $embed['status']['license'];
$duration= $embed['contentDetails']['duration'];
}
echo $emb;
echo $license;
echo $duration;
It's not a function, but this will do the tric :)

OpenERP 7 API invoice validation and payment

I am working with OpenERP 7's XML-RPC API and I am trying to validate an invoice and apply a payment but I can't figure out what model I should be using.
I have successfully created an invoice and added lines. There doesn't seem to be anything in account.invoice and account.payment.term and payment.order do not seem to work either.
Any help would be appreciated.
Hi i figured out how to validate payment to an invoice automatically via XML-RPC using php.
This how openERP invoice workflow works for the payment.
When you create an invoice, payment to this invoice is done by a voucher i.e. model account.voucher is used to apply a payment to an invoice. So when you create an invoice and validate it, the invoice changes status to open of which you can now access the "customer payments" menu and enter the customer name, the onchange_partner_id() function defined in account.voucher is executed to make a calculation of all the invoices the currently enter partner has open for payments.
Then when you enter the payment to make in "Paid Amount" field, onchange_payment() function is executed to allocate the amount paid to different open invoices of the selected partner.
And when you click validate on the payment form, automatically openerp pays the invoice and marks it as paid.
This therefore means you should atleast understand how openerp handles invoices and payments to that invoice by studying the python code in modules account and account_voucher To make the long story short, this is the code that i used.
First create an invoice for a particular partner and validate it. make sure that you partner has a valid phone number set in res.partner model. (Just create it using openerp forms)
************** php code **********
<?php
error_reporting(1);
/*
* TODO
* Improve on handling of server responses. Success and Failures
*/
date_default_timezone_set('Europe/Moscow');
include_once("openerp_models.php");
/////////////////////////////////////////////////////////////////////
//confirm that a username and password is set
if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_PW']) {
//password and username -- Basic Authentication
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
///important parameters
$phone_no = $_REQUEST['sender_phone']; //get the mobile number. Use this number to get the partner information.
$amount = $_REQUEST['amount']; // get amount from url
$amount_again = $_REQUEST['amount']; //this will be displayed to the paying client. $amount above is reduced to zero hence
//we create another amount variable to show the customer with success message.
$payment_ref = $_REQUEST['k2_transaction_id']; // get this from url
$firstname = $_REQUEST['first_name'];
$lastname = $_REQUEST['last_name'];
$middlename = $_REQUEST['middle_name'];
$service_name = $_REQUEST['service_name'];
$business_number = $_REQUEST['business_number'];
$transaction_reference = $_REQUEST['transaction_reference'];
$internal_transaction_id = $_REQUEST['internal_transaction_id'];
$transaction_timestamp = $_REQUEST['transaction_timestamp'];
$transaction_type = $_REQUEST['transaction_type'];
$account_number = $_REQUEST['account_number'];
$currency = $_REQUEST['currency'];
$signature = $_REQUEST['signature'];
//openerp instance, pass login,password,dbname and serverURL
$kengen_model = new OpenERPXmlrpc($username, $password, 'copia_training_db', 'http://127.0.0.1:8069/xmlrpc/');
/* TODO UNCOMMENT THIS CODE FOR ACTUAL TESTING WITH KOPOKOPO SERVER
* We will then authorize kopokopo to continue with record creation. But before that,
* we should make sure that the request is actually coming from kopokopo using the signature value sent.
* To learn more see https://app.kopokopo.com/push_api
*
//set up base string
$base_string = "account_number=".$account_number."&amount=".$amount."&business_number=".$business_number."&"
. "currency=".$currency."&first_name=".$firstname."&internal_transaction_id=".$internal_transaction_id."&"
. "last_name=".$lastname."&middle_name=".$middlename."&sender_phone=".$phone_no."&service_name=".$service_name."&transaction_reference=".$transaction_reference."&"
. "transaction_timestamp=".$transaction_timestamp.""
. "transaction_type=".$transaction_type." ";
//get the symmetric key from table keys.api. This key should be copied from Your KopoKopo Account
$get_key = $kengen_model->search('keys.api', 'provider_name', '=', 'KopoKopo') ;
$key_id = $get_key[0];
$key_value = '' ;
//we read
$read_keys = $kengen_model->read('keys.api', [$key_id]);
//loop
foreach ($read_keys as $keys => $values) {
$value = $values->scalarval();
// print_r($value);
// print '<br/>';
//$myarray [] = array($value['name']->scalarval());
$key_value = $value['key_value']->scalarval();
}
// print $key_value; exit;
//data to use
$hash_data = hash_hmac('sha256', $base_string, $key_value, true);
//generate our own signature to compare with
$signature_to_test = base64_encode($hash_data) ;
///test if the parameter $signature passed by KopoKopo is equal to $signature_to_test
// print $signature_to_test;
* TODO, DO the actual testing with Real KEY_VALUE and Request from kopokopo and only allow execution if
* $signature_to_test = $signature else return an access denied status
*/
/////////////////////////////////////////
/* We retrieve the payment journal for kopokopo. We will
* use the journal code to retrieve the journal id.
* The code for kopokopo should be KPKPJ
*/
$get_jrnl_code = $kengen_model->search('account.journal', 'code', '=', 'KPKPJ') ;
$journal_id = $get_jrnl_code[0]; //kopokopo journal
/*
* We retrieve the account_id to pay to. This code is code for KopoKopo Account
* should be static i.e. 2040 is the account unless otherwise specified.
*/
$get_acc_code = $kengen_model->search('account.account', 'code', '=', '2040') ;
$account_id = $get_acc_code[0]; //kopokopo account
//for this record to appear on list of customer payment
$type = 'receipt';
//
/* TODO
* after a successful login, we must authorize this user. We do this to make sure that
* the request if coming from kopokopo server.
*/
//now search for the partner using phone/mobile number parameter
$search_partner = $kengen_model->search('res.partner', 'phone', '=', $phone_no);
//check to make sure that the customer exists
//create an array
$ids = array();
//loop through the $search content and assign its contents to the $ids
for ($i = 0; $i <= count($search_partner); $i++) {
// print $search_partner[$i];
$ids [] = $search_partner[$i];
}
// if a user exist we continue processing
if (count($ids[0]) > 0) {
//perform a read, by picking the first item on the array
$read = $kengen_model->read('res.partner', [$ids[0]]);
// print_r($read);
$myarray = null;
$client_name = '';
//this foreach loop with only loop once. hence just retrieve the client name and amount saved
// in openerp
foreach ($read as $keys => $values) {
$value = $values->scalarval();
// print '<br/>';
//$myarray [] = array($value['name']->scalarval());
$client_name = $value['name']->scalarval();
}
/////////////////////////////////////////////////////
//get invoices, pass partner_id and invoice status which is open for unpaid invoices
//get invoices to retrieve the journal id
$get_invoices = $kengen_model->getPartnetInvoices('account.voucher', $ids[0], 'open');
$retrieved_pay_account_id = 0;
$pay_journal_id = 0;
$period_id = 0;
foreach ($get_invoices as $keys => $values) {
$value = $values->scalarval();
$retrieved_pay_account_id = $value[4]->scalarval();
$pay_journal_id = $value[5]->scalarval();
$period_id = $value[6]->scalarval();
$move_id = $value[7]->scalarval();
}
// print $retrieved_account_id;
/////////////////////////////////////////////////////
//fields to create
$account_voucher_fields = array(
'partner_id' => $ids[0],
'amount' => $amount,
'reference' => $payment_ref,
'journal_id' => $journal_id,
'account_id' => $account_id,
// 'move_id' => $move_id ,
// 'journal_id'=> $retrieved_journal_id,
'type' => $type);
//voucher payment
$create_kopokopo_payment = $kengen_model->createRecord($account_voucher_fields, 'account.voucher');
//we get the total amount of invoice available for this customer.
$total_invoices_amount = $kengen_model->getPartnetInvoices('account.voucher', $ids[0], 'open');
$invoice_totals = 0;
foreach ($total_invoices_amount as $keys => $values) {
$value = $values->scalarval();
$invoice_totals += $value[3]->scalarval();
///
}
// print 'invoice totals is '.$invoice_totals ;
//voucher line payment
//we will retrieve all invoices available for this partner
//get invoices, pass partner_id and invoice status which is open for unpaid invoices
$invoices = $kengen_model->getPartnetInvoices('account.voucher', $ids[0], 'open');
//loop through available invoices. Remember that a customer can have more than one open invoice
$total_credit = 0;
foreach ($invoices as $keys => $values) {
$value = $values->scalarval();
$number = $value[1]->scalarval();
$invoice_amount_to_pay = $value[3]->scalarval();
/*
* To undestand how this code works look at account.voucher model in openerp
* function recompute_voucher_lines(). This openerp function calculates voucher lines given
* a particular payment.
*/
$min_amount = min($invoice_amount_to_pay, $amount);
//
/* print 'x';
print 'on existing invoices in ELSE IF >>>' . ($min_amount);
print '<br/>';
print 'amount_unreconciled is >>>' . ($invoice_amount_to_pay);
print '<br/>';
print 'total_credit is >>>' . $amount;
print '<br/>'; */
///
//reduce amount paid
$amount -= $min_amount;
//convert amount into int
$amount_to_allocate = intval($min_amount);
// print $amount_total ;
///get invoice move line ids
$new_number = str_replace('/', '', $number); //convert the invoice line
$move_ids = $kengen_model->search('account.move.line', 'ref', '=', $new_number);
/////
$account_voucher_line_fields = array(
'partner_id' => $ids[0],
'voucher_id' => $create_kopokopo_payment, //last id inserted in account.voucher
'account_id' => $retrieved_pay_account_id,
'move_line_id' => $move_ids[0],
'amount' => $amount_to_allocate,
'type' => 'cr',
'name' => $number,);
//////
$create_kopokopo_line_payment = $kengen_model->createRecord($account_voucher_line_fields,
'account.voucher.line');
}
/*
* we validate the payment. We access method button_proforma_voucher declared in model account.voucher
* This methods validates an invoice payment and does reconcilation process for us if the user has paid
* fully else the method reconciles invoice partially.
*/
$validate_voucher_payment = $kengen_model->call_function_func('account.voucher',
'button_proforma_voucher', array($create_kopokopo_payment));
//customer found. Return a json response for KopoKopo
$message = "Thank you " . $client_name . " for your payment of Ksh " . $amount_again . ". We value your business";
// see doc # https://app.kopokopo.com/push_api
$success_response = array("status" => "01", "description" => "Accepted",
"subscriber_message" => $message);
echo json_encode($success_response);
return json_encode($success_response);
}
// else we return a json_response with error message
else {
//customer not found. Return a json response for KopoKopo
// see doc # https://app.kopokopo.com/push_api
$error_response = array("status" => "02", "description" => "Account not found");
echo json_encode($error_response);
return json_encode($error_response);
}
} else {
header('WWW-Authenticate: Basic realm="Copia ERP"');
header('HTTP/1.0 401 Unauthorized');
print 'Access Denied';
exit();
}
?>
Hope this will help you.

Exporting Invoices from Magento

I have been trying to export all of our invoices in a specific format for importing into Sage accounting. I have been unable to export via Dataflow as I need to export the customer ID (which strangely is unavailable) and also a couple of static fields to denote tax codes etc…
This has left me with the option of using the API to export the data and write it to a CSV. I have taken an example script I found (sorry can’t remember where in order to credit it...) and made some amendments and have come up with the following:
<?php
$website = 'www.example.com';
$api_login = 'user';
$api_key ='password';
function magento_soap_array($website,$api_login,$api_key,$list_type,$extra_info){
$proxy = new SoapClient('http://'.$website.'/api/soap/?wsdl');
$sessionId = $proxy->login($api_login, $api_key);
$results = $proxy->call($sessionId,$list_type,1);
if($list_type == 'order_invoice.list'){
/*** INVOICES CSV EXPORT START ***/
$filename = "invoices.csv";
$data = "Type,Account Reference,Nominal A/C Ref,Date,Invoice No,Net Amount,Tax Code,Tax Amount\n";
foreach($results as $invoice){
foreach($invoice as $entry => $value){
if ($entry == "order_id"){
$orders = $proxy->call($sessionId,'sales_order.list',$value);
}
}
$type = "SI";
$nominal = "4600";
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, $invoice['created_at']);
$invoicedOn = $date->format('d/m/Y');
$invoiceNo = $invoice['increment_id'];
$subtotal = $invoice['base_subtotal'];
$shipping = $invoice['base_shipping_amount'];
$net = $subtotal+$shipping;
$taxCode = "T1";
$taxAmount = $invoice['tax_amount'];
$orderNumber = $invoice['order_id'];
foreach($orders as $order){
if ($order['order_id'] == $orderNumber){
$accRef = $order['customer_id'];
}
}
$data .= "$type,$accRef,$nominal,$invoicedOn,$invoiceNo,$net,$taxCode,$taxAmount\n";
}
file_put_contents($_SERVER['DOCUMENT_ROOT']."/var/export/" . $filename, "$header\n$data");
/*** INVOICES CSV EXPORT END ***/
}else{
echo "nothing to see here";
}/*** GENERIC PAGES END ***/
}/*** END function magento_soap_array ***/
if($_GET['p']=="1")
{
magento_soap_array($website,$api_login,$api_key,'customer.list','Customer List');
}
else if($_GET['p']=="2")
{
magento_soap_array($website,$api_login,$api_key,'order_creditmemo.list','Credit Note List');
}
else if($_GET['p']=="3")
{
magento_soap_array($website,$api_login,$api_key,'sales_order.list','Orders List');
}
else if($_GET['p']=="4")
{
magento_soap_array($website,$api_login,$api_key,'order_invoice.list','Invoice List');
}
?>
This seems to be working fine, however it is VERY slow and I can’t help but think there must be a better, more efficient way of doing it…
Has anybody got any ideas?
Thanks
Marc
i think on put break; would be okey. because only one key with order_id, no need to looping after found order_id key.
if ($entry == "order_id"){
$orders = $proxy->call($sessionId,'sales_order.list',$value);
break;
}
and you can gather all call(s) and call it with multicall as example:
$client = new SoapClient('http://magentohost/soap/api/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'somestuff.method');
$result = $client->call($session, 'somestuff.method', 'arg1');
$result = $client->call($session, 'somestuff.method', array('arg1', 'arg2', 'arg3'));
$result = $client->multiCall($session, array(
array('somestuff.method'),
array('somestuff.method', 'arg1'),
array('somestuff.method', array('arg1', 'arg2'))
));
// If you don't need the session anymore
$client->endSession($session);
source

How to use alphauserpoints credits towards adsmanager payment in joomla?

Are there any plugins or hacks that let me use alphauserpoints credits towards payments for adsmanager adverts in joomla?
Here is my solution for Alphauserpoints 1.7.4, Adsmanager 2.7 RC3 and PaidSystem.
Edit components\com_paidsystem\api.paidsystem.php
After defined('_JEXEC') or die( 'Restricted access' ); add the below code
//AlphaUserPoints start
$api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
if ( file_exists($api_AUP))
{
require_once ($api_AUP);
}
//AlphaUserPoints end
Next you need to edit function getBalance($userid). This is in api.paidsystem.php
function getBalance($userid)
{
//Alphauserpoints substitute for value
//Get the RefferreID of a user
$referreid = AlphaUserPointsHelper::getAnyUserReferreID((int)$userid);
$profil=AlphaUserPointsHelper:: getUserInfo ($referreid);
$value=$profil->points;
//Alphauserpoints substitute for value end
//ORIGINAL CODE BELOW
/*$db =JFactory::getDbo();
//$db->setQuery( "SELECT credit FROM #__paidsystem_credits WHERE userid=".(int)$userid );
//To explicitly convert a value to integer, use either the (int) or (integer) casts.
$value = $db->loadResult();*/
if ($value == "")
$value = 0;
return $value;
}
Then edit the next function
//EDIT this to debit credits from alphauserpoints
//Use alphauserpoints rule to debit from alphauserpoints.
function removeCredits($userid,$num,$description)
{
$db =JFactory::getDbo();
//$db->setQuery( "SELECT credit FROM #__paidsystem_credits WHERE userid=".(int)$userid );
//$balance = (float) $db->loadResult();
$referreid = AlphaUserPointsHelper::getAnyUserReferreID((int)$userid);
$profil=AlphaUserPointsHelper:: getUserInfo ($referreid);
$balance=$profil->points;
//$db->setQuery( "UPDATE #__paidsystem_credits SET credit=credit-".(float)$num." WHERE userid=".(int)$userid );
//$db->query();
echo "removeCredits=$userid,$num";
$obj = new stdClass();
$obj->userid = $userid;
$obj->balance = $balance;
$obj->change = $num * -1;
$obj->description = $description;
$obj->date = date("Y-m-d H:i:s");
AlphaUserPointsHelper::newpoints( 'plgaup_purchaseadvertising', '','', 'purchase advertising', $num*-1);
$db->insertObject("#__paidsystem_history",$obj);
}
REMEMBER: You will need to create a new rule in the administrator section of the alphauserpoints component in Joomla for this to work. In my code the new rule name was called plgaup_purchaseadvertising.

Categories