integrate razorpay payment module in zenkart - zen-cart

i am trying to integrate razorpay payment module in zenkart.
i added module in includes/modules/payment
here is my code
function process_button() {
$displayCurrency = 'INR';
$api = new Api($keyId, $keySecret);
$orderData = [
'receipt' => 3456,
'amount' => 2000 * 100, // 2000 rupees in paise
'currency' => 'INR',
'payment_capture' => 1 // auto capture
];
$razorpayOrder = $api->order->create($orderData);
$razorpayOrderId = $razorpayOrder['id'];
$_SESSION['razorpay_order_id'] = $razorpayOrderId;
$displayAmount = $amount = $orderData['amount'];
if ($displayCurrency !== 'INR'){
$url = "https://api.fixer.io/latest?symbols=$displayCurrency&base=INR";
$exchange = json_decode(file_get_contents($url), true);
$displayAmount = $exchange['rates'][$displayCurrency] * $amount / 100;
}
return ' <script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="'.$keyId.'"
data-amount="'.$amount.'"
data-currency="INR"
data-name="ganesh"
data-image="https://s29.postimg.org/r6dj1g85z/daft_punk.jpg"
data-description="desg ga"
data-prefill.name=ganesh"
data-prefill.email="xxxx#gmail.com"
data-prefill.contact="999999999"
data-notes.shopping_order_id="3456"
data-order_id="'.$razorpayOrderId.'"
data-display_amount="'.$displayAmount.'"
data-display_currency="'.$displayAmount.'"
>
</script>
<input type="hidden" name="shopping_order_id" value="3456">';
}
i know my code is not working. i am new at zenkart i have php code for zenkart its working but i cant run this code zenkart. please help me to solve this problem

Related

How do i store pictures in moodle?

I'm trying to create my own Activity in moodle where students can take pictures of their Drivers License and that pictures get stored in moodle, then later opended and shown to the teacher.
My Problem is to store the picture on the moodle side and not downloading it.(like i'm doing right now)
Hopfully someone can help me figure out a way to use the file_storage given by moodle to safe the pictures.
kind regards
J
This is my code for now (view.php) ... I know its not realy in a moodle way but im trying to get it to work first then then clean up the code
require_once('../../config.php');
require_once($CFG->dirroot . '/mod/driverslicense/lib.php');
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/driverslicense/classes/submit/submit.php');
require_once("$CFG->libdir/formslib.php");
$id = required_param('id', PARAM_INT);
list ($course, $cm) = get_course_and_cm_from_cmid($id, 'driverslicense');
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/driverslicense:view', $context);
$driverslicense = new assign($context, $cm, $course);
$urlparams = array('id' => $id,
'action' => optional_param('action', '', PARAM_ALPHA),
'rownum' => optional_param('rownum', 0, PARAM_INT),
'useridlistid' => optional_param('useridlistid', $driverslicense->get_useridlist_key_id(), PARAM_ALPHANUM));
$url = new moodle_url('/mod/driverslicense/view.php', $urlparams);
$PAGE->set_url($url);
// Update module completion status.
$driverslicense->set_module_viewed();
// Apply overrides.
$driverslicense->update_effective_access($USER->id);
// Get the driverslicense class to
// render the page.
//echo $driverslicense->view(optional_param('action', '', PARAM_ALPHA));
$mform = new submit();
echo $OUTPUT->header();
echo '<body>
<div id="container">
<video autoplay="true" id="video"></video>
<button id="btn"> Take Picture </button>
<canvas id="canvas" class="hidden"></canvas>
<a id="dl-btn" href="frontpic" download="image.png" class="hidden"></a>
</div>
</body>';
$fs = get_file_storage();
// Prepare file record object
$fileinfo = array(
'contextid' => $context->id, // ID of context
'component' => 'mod_driverslicense', // usually = table name
'filearea' => 'driverslicense', // usually = table name
'itemid' => 0, // usually = ID of row in table
'filepath' => '/', // any path beginning and ending in /
'filename' => 'driverslicensefront.png'); // any filename
$fs->create_file_from_url($fileinfo, imgURL );
echo $OUTPUT->footer();
?>
<script type="text/javascript">
const video = document.querySelector('#video')
const btn = document.querySelector('#btn')
const canvas = document.querySelector('#canvas')
if ('mediaDevices' in navigator && 'getUserMedia' in navigator.mediaDevices) {
navigator.mediaDevices.getUserMedia({video: true})
.then(stream => {
video.srcObject = stream
})
.catch(error => {
console.log('An error occured while accessing webcam.')
})
}
btn.addEventListener('click', () =>{
const width = video.videoWidth, height = video.videoHeight
const context = canvas.getContext('2d')
canvas.width = width
canvas.height = height
context.drawImage(video, 0, 0, width, height)
const imgURL = canvas.toDataURL('image/png')
document.querySelector('#dl-btn').href = imgURL
document.querySelector('#dl-btn').click()
})
</script>

PrestaShop 1.6 How to add a discount to order?

I'm writing a module for PRESTASHOP 1.6. One of the task of this module is to give a customer DISCOUNT for whole order in the CART and display it. The question is which method should I use to get total value of all products in the cart and then add a single DISCOUNT for whole order?
Check this code to create a new cart rule:
$cart_rule = new CartRule();
$cart_rule->id_customer = $this->context->cart->id_customer;
$cart_rule->name = array(
Configuration::get('PS_LANG_DEFAULT') => $this->l('CartRule title')
);
$cart_rule->date_from = date('Y-m-d H:i:s', time());
$cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600);
$cart_rule->quantity = 1;
$cart_rule->quantity_per_user = 1;
$cart_rule->minimum_amount_currency = $this->context->cart->id_currency;
$cart_rule->reduction_currency = $this->context->cart->id_currency;
$cart_rule->free_shipping = true;
$cart_rule->reduction_amount = 50; #discount value
$cart_rule->active = 1;
$cart_rule->add();
// Add cart rule to cart and in order
$values = array(
'tax_incl' => $cart_rule->getContextualValue(true),
'tax_excl' => $cart_rule->getContextualValue(false)
);
$this->context->cart->addCartRule($cart_rule->id, $cart_rule->name[Configuration::get('PS_LANG_DEFAULT')], $values);

Missing "Buyer Information" in Recurring Payment

We're using the PayPal PHP SDK to create a "Recurring Payments Profile", but every profile is missing the "Buyer Information" (Name & Email) under "History" in our Sandbox account.
How can we add the buyer's name and email address to the request?
$firstName = $_POST[ 'firstName' ];
$lastName = $_POST[ 'lastName' ];
$email = $_POST[ 'email' ];
$installment_amount = ...;
$shippingAddress = new AddressType();
$shippingAddress->Name = $firstName . ' ' . $lastName;
$shippingAddress->Street1 = $_POST[ 'address1' ];
$shippingAddress->Street2 = $_POST[ 'address2' ];
$shippingAddress->CityName = $_POST[ 'city' ];
$shippingAddress->StateOrProvince = $_POST[ 'state' ];
$shippingAddress->PostalCode = $_POST[ 'zip' ];
$shippingAddress->Country = $_POST[ 'country' ];
$shippingAddress->Phone = $_POST[ 'phone' ];
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $firstName . ' ' . $lastName;
$RPProfileDetails->BillingStartDate = date( DATE_ATOM );
$RPProfileDetails->SubscriberShippingAddress = $shippingAddress;
$activationDetails = new ActivationDetailsType();
$activationDetails->InitialAmount = new BasicAmountType( 'USD', $installment_amount );
$activationDetails->FailedInitialAmountAction = 'CancelOnFailure';
$paymentBillingPeriod = new BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = 1;
$paymentBillingPeriod->BillingPeriod = 'Day';
$paymentBillingPeriod->TotalBillingCycles = 2;
$paymentBillingPeriod->Amount = new BasicAmountType( 'USD', $installment_amount );
$scheduleDetails = new ScheduleDetailsType();
$scheduleDetails->Description = ...;
$scheduleDetails->ActivationDetails = $activationDetails;
$scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
$scheduleDetails->MaxFailedPayments = 3;
$scheduleDetails->AutoBillOutstandingAmount = 'AddToNextBilling';
$createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
$cardDetails = new CreditCardDetailsType();
$cardDetails->CreditCardNumber = $_POST[ 'creditCardNumber' ];
$cardDetails->CreditCardType = $_POST[ 'creditCardType' ];
$cardDetails->ExpMonth = $_POST[ 'expDateMonth' ];
$cardDetails->ExpYear = $_POST[ 'expDateYear' ];
$cardDetails->CVV2 = $_POST[ 'cvv2Number' ];
$createRPProfileRequestDetail->CreditCard = $cardDetails;
$createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
$createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
$createRPProfileReq = new CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
$paypalService = new PayPalAPIInterfaceServiceService( ... );
try {
$createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile( $createRPProfileReq );
} catch ( Exception $exception ) {
...
}
As long as you are passing the shipping information in the Profile Details it should get passed into the transaction information in Sandbox. Billing address is not stored in the PayPal Transactions.
Your code looks like it should be passing the information correctly. As a just in case, look over the below sample code from GitHub. I didn't paste all of the code in.
Merchant SDK php Sample for Recurring Billing
$shippingAddress = new AddressType();
$shippingAddress->Name = $_REQUEST['shippingName'];
$shippingAddress->Street1 = $_REQUEST['shippingStreet1'];
$shippingAddress->Street2 = $_REQUEST['shippingStreet2'];
$shippingAddress->CityName = $_REQUEST['shippingCity'];
$shippingAddress->StateOrProvince = $_REQUEST['shippingState'];
$shippingAddress->PostalCode = $_REQUEST['shippingPostalCode'];
$shippingAddress->Country = $_REQUEST['shippingCountry'];
$shippingAddress->Phone = $_REQUEST['shippingPhone'];
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $_REQUEST['subscriberName'];
$RPProfileDetails->BillingStartDate = $_REQUEST['billingStartDate'];
$RPProfileDetails->SubscriberShippingAddress = $shippingAddress;
$activationDetails = new ActivationDetailsType();

TYPO3 6.1 - how can I login a fe_user via code?

I am using TYPO3 6.1 and try to login a FE user via Code (included via PHP and USER_INT).
This code does not work for me. :( Any ideas why?
// try to login the user now
$loginData = array(
'uname' => trim($postData['username']), //usernmae
'uident' => trim($postData['password']), //password
'status' => 'login'
);
// $GLOBALS['TSFE']->fe_user-checkPid=0; //do not use a particular pid
$GLOBALS['TSFE']->fe_user->checkPid = $this->feUserPid; // ''; //do not use a particular pid
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
//
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord(
$info['db_user'], $loginData['uname']
);
$ok = $GLOBALS['TSFE']->fe_user->compareUident($user, $loginData);
//
if($ok)
{
// login successfull
$GLOBALS['TSFE']->fe_user->createUserSession($user);
//
$content = '<h3 class="green">LOGIN OK!</h3>';
$content .= '<p>Sie sind eingeloggt als ' . $feUsername . ' und wurden nun weitergeleitet...</p>';
}
else
{
// login failed
$content = '<h3 class="red">LOGIN FAILED!</h3>';
}
Thanks for any hint!
Starting with TYPO3 4.7, you must use $loginData['uident_text'] instead of $loginData['uident'] for the password.
If the problem persists, please give more information what exactly is going wrong, what your log says etc.
Does compareUident() return TRUE for you?
I, fx have a case, where I automatically log in user that has just created themselves. And compareUident() didn't work for me for some reason, but as I know this same website visitor just created the user, I skip that function and continue on initiating all the session variables. The following is a working code on TYPO3 6.1:
$loginData = array(
'uname' => $postdata['username'],
'uident' => $postdata['password'],
'status' => 'login',
);
$GLOBALS['TSFE']->fe_user->checkPid = 0;
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'], $loginData['uname']);
//if($GLOBALS['TSFE']->fe_user->compareUident($user, $loginData)) {
$GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->fetchUserSession();
$GLOBALS['TSFE']->loginUser = 1;
$GLOBALS['TSFE']->fe_user->fetchGroupData();
$GLOBALS['TSFE']->fe_user->start();
$GLOBALS['TSFE']->fe_user->createUserSession($user);
$GLOBALS['TSFE']->fe_user->loginSessionStarted = TRUE;
//}
Inspired by:
https://stackoverflow.com/a/7738383/445364
https://typo3.org/extensions/repository/view/dix_easylogin

Setting starting value for Google Line Chart dynamically and redrawing chart

I am using the code below to generate a line chart for a projected financial balance. Data is generated from information in a MySQL database. What I would like to be able to do is to have a form with an input field on the page that allows the user to set the starting balance dynamically once the page is loaded, such that the chart is redrawn with the correct starting balance, but I can't work out how to do this:
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'Date', 'type' => 'string'),
array('label' => 'Amount', 'type' => 'number')
);
[code to generate data goes here - i.e. calculating a balance for each date in the chart]
$balance = $balance - $monthly - $weekly + $session_total;
$temp = array();
$temp[] = array('v' => (string) $date_display);
$temp[] = array('v' => (string) $balance);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
//echo $jsonTable;
?>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var formatter = new google.visualization.NumberFormat({fractionDigits:2,prefix:'\u00A3'});
formatter.format(data, 1);
var options = {
pointSize: 5,
legend: 'none',
hAxis: { showTextEvery:31 },
series: {0:{color:'2E838F',lineWidth:2}},
chartArea: {left:50,width:"95%",height:"80%"},
backgroundColor: '#F7FBFC',
height: 400
};
// Instantiate and draw our chart, passing in some options.
//do not forget to check ur div ID
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div"></div>
Hopefully there's a fairly simple way to refresh the chart when new data is available. It requires a small change to your PHP and a few JavaScript tweaks.
The nice thing about using Google Charts is that you can just re-draw them by calling drawChart() again, you just need to be able to modify the data before you do it.
The change I would make the PHP would be to store the original value, so that when you want to change the value according to the user's input you can always have something to refer back to:
// display the date
$temp[] = array('v' => (string) $date_display);
// the data used by the chart
$temp[] = array('v' => (string) $balance);
// the original value
$temp[] = array('v' => (string) $balance);
I would also make the table data global rather than drawing it directly into the function, this way you can change it and refresh the chart quite easily.
var table = <?php echo $jsonTable; ?>;
function drawChart() {
var data = new google.visualization.DataTable(table);
......
}
I tested this with a basic form that looks like this:
<form method="post" action="#" onsubmit="return false;">
<input type="text" id="balance1" />
<input type="text" id="balance2" />
<button onclick="return refreshChart()">Go</button>
</form>
Clicking on the button cancels the default action and calls a function called refreshChart(). This function takes the value and adds it to the original values on the fly before re-drawing the chart:
function refreshChart() {
var balance1 = document.getElementById('balance1').value;
var balance2 = document.getElementById('balance2').value;
if(!balance1) {
balance1 = 0;
}
if(!balance2) {
balance2 = 0;
}
for(var i = 0, length = table.rows.length; i < length; i++) {
table.rows[i].c['1'].v = parseFloat(table.rows[i].c['2'].v) + parseFloat(balance1) + parseFloat(balance2);
}
drawChart();
return false;
}
It takes the balance entered and adds it to the original value stored in table.rows[i].c['2'].v and overwrites the value in table.rows[i].c['1'].v which is used by the chart. It then calls the original drawChart() function but the new data is used.
I played around with some default data and this is the output I tested it with on JSFiddle.