Want to show allowed payment methods on checkout page of OpenCart - paypal

Hey StackOverflow Experts !
I want to show allowed payment methods on checkout page (OpenCart) according to the selected currency by visitor.
Example:
Show Ccavenue payment method if the selected currency is INR. Like PayPal payment module does it - shows if the selected currency is USD. Exactly the same I want in my Ccavenue module.
So how can I do it?
Any suggestion or solution would by appreciated.

create file & class in catalog\model\payment\ e.g ccavenue.php or wht your requirements
then create function as shown below hope it helps
public function your_function() {
$currencies = array(
'INR'
);
if (!in_array(strtoupper($this->currency->getCode()), $currencies)) {
$status = false;
}
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'your_pg',
'title' => $this->language->get('text_title'),
'sort_order' => $this->config->get('your_pg_sort_order')
);
}
return $method_data;
}
you can put different currency in array e.g AUD etc

Related

Logic hook "After save" not working with Subpanel

I am trying to calculate total amount using logic hook.
I have two modules. Accounts and Payments having 1:M Relationship
I have written logic hook after save in payments module.
$hook_array['after_save'][] = Array(1, 'Update pending amount and paid amount in case', 'custom/modules/Payments/logic_hooks_class.php','logic_hooks_class', 'after_save_method');
Its working if I add Payment directly from payment module. But when I trying to insert Payment in accounts module thorugh payment subpanel then its not calling after save logic hook.
I have also checked with process record logic hook.
Could you please someone help me resolve this. I am using SuiteCRM 7.6.4
Thanks in advance.
Try to use
For more info try this link Click here ....
after_relationship_add
Example
./custom/modules/{module}/logic_hooks.php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'after_relationship_add example',
//The PHP file where your class is located.
'custom/modules/{module}/logic_hooks_class.php',
//The class the method is in.
'logic_hooks_class',
//The method to call.
'after_relationship_add_method'
);
/custom/modules/{module}/logic_hooks_class.php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class logic_hooks_class
{
function after_relationship_add_method($bean, $event, $arguments)
{
// check $arguments.related_module == "Payments"
//logic
}
}

Interaction between two forms in a single controller

I'm trying to work with two forms in a single controller in Symfony2. The page is displaying a list of e-mail addresses with checkboxes to select them.
The first form is a research form and the second is used to remove e-mail addresses. There is also a pagination in my page.
My problem is that I can't remove an e-mail address with a research when the e-mail address is not displayed in the first page.
public function emailsAction(Request $request, $paginationParams)
{
$searchForm = $this->createForm(new SearchFormType(), null, array());
$searchForm->handleRequest($request);
if ($searchForm->isValid()) {
// FETCH E-MAILS WITH SEARCH
} else{
// FETCH E-MAILS WITHOUT SEARCH
}
// here I slice the result depending on the pagination params
$removeForm = $this->createForm(new RemoveFormType(), null, array(
'emails' => $emails
));
$removeForm->handleRequest($request);
if ($removeForm->isValid())
{
$formData = $removeForm->getData();
// here I remove the e-mails
}
...
$params['remove_form'] = $manageSubscribersForm->createView();
$params['search_form'] = $searchAbonneActuForm->createView();
return $this->renderView('my_template.html.twig', $params);
}
If I understand it correctly, the problem is that my removeForm is created with the spliced array and without the search applied when handling the removeForm.
When I search for a name, say johnsmith, it displays me on page 1, one result which is johnsmith#email.com.
If johnsmith#email.com is on page 2 without search, the removeForm handling my request is created with a spliced array not containing johnsmith, so the removeForm is not considered valid.
How should I do to create my removeForm, taking account of the search done before when submitting the removeForm? Or maybe I'm doing this wrong ?
I'm not a native english speaker so if anything is not clear, feel free to ask.
You can use a hidden field with the current page index, that will help you make your search again.
Or you can use an event listener to modify the form field before the submission for the validation.

Field validations in sugarcrm

I just started using SugarCRM CE for the first time (Version 6.5.15 (Build 1083)). I'm quite impressed with the ease of use when adding new fields or modules, but there's one quite indispensable thing that seems to be missing: Validation of user input.
I would for example like to check a lot of things:
Check if a emailadres has a valid format, using some regular expression
Check if a postalcode exists (maybe do a webswervice call to validate it)
Do a calculation to see if a citizen service number is valid
etc.
The only thing I seem to be able to do in studio is make a field required or not, there doesn't seem to be any standard way to execute a validation on a field.
All I can find when I google on it is lots of ways to hack into the source code, like this one: http://phpbugs.wordpress.com/2010/01/22/sugarcrm-adding-javascript-validation-on-form-submit/ And even then I don't find any examples that actually do a validation.
Am I just missing something? Or is editing source code the only way to add this?
I don't think the "standard" validations are available in the CE edition.
What surprises me is that you can't define a validation somewhere and attach it to a field. I kind of expected this, since the rest of the system is very well structured (modules, packages, etc..)
I now for instance created a 11-check, this is a very specific check for a dutch bank account number. to get this to work, I did the following (based upon examples I found googling around):
I added the bank account to contacts in studio and after that edited \custom\modules\Contacts\metadata\editviewdefs.php
I added the following snippets:
'includes'=> array(
array('file'=>'custom/modules/Contacts/customJavascript.js')),
array (
0 =>
array(
'customCode' =>
'<input title="Save [Alt+S]" accessKey="S" onclick="this.form.action.value=\'Save\'; return check_custom_data();" type="submit" name="button" value="'.$GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL']>',
),
1 =>
array(
'customCode' =>
'<input title="Cancel [Alt+X]" accessKey="X" onclick="this.form.action.value=\'index\'; this.form.module.value=\''.$module_name.'\'; this.form.record.value=\'\';" type="submit" name="button" value="'.$GLOBALS['app_strings']['LBL_CANCEL_BUTTON_LABEL'].'">'
)
),
And in customJavascript.js i placed this code:
function check_custom_data()
{
if (!eleven_check(document.getElementById("bankaccount_c").value)){
alert ('Bank account not valid');
return false;
} else {
return check_form('EditView');
}
function eleven_check(bankaccount) {
bankaccount=bankaccount.replace(/\D/, "");
charcount=bankaccount.length;
var som=0;
for (i=1; i<10; i++) {
getal=bankaccount.charAt(i-1);
som+=getal*(10-i);
}
if (som % 11==0 && charcount==9) {
return true
} else {
return false
}
}
}
This check now works the way I want it to work, but I'm wondering if this is the best way to add a validation. this way of adding a validation doesn't however accommodate PHP validations, for instance, if I want to validate against some data in the database for one or another reason, I would have to use ajax calls to get that done.
Email validation is in the pro edition, I had assumed it was in CE as well but I'm not 100% sure.
The other 2 are a lot more specific - postcode validation would depend upon your country so would be difficult to roll out. For these you will need to write your own custom validation.
I know its late, but maybe still someone needs this.
You can just add your custom javascript validation as a callback in your vardefs like this:
'validation' =>
array (
'type' => 'callback',
'callback' => 'function(formname,nameIndex){if($("#" + nameIndex).val()!=999){add_error_style(formname,nameIndex,"Only 999 is allowed!"); return false;}; return true;}',
),
I documented it here as its not well documented elsewhere:
https://gunnicom.wordpress.com/2015/09/21/suitecrm-sugarcrm-6-5-add-custom-javascript-field-validation/
You can add custom validation code to the following file: ./custom/modules/.../clients/base/views/record/record.js
There you can add validation code. In this example, I will validate if the phone_number is not empty when an accounts has a customer-type:
EXAMPLE CODE IN RECORD.JS:
({
extendsFrom: 'RecordView',
initialize: function (options) {
app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});
//add validation
this.model.addValidationTask('check_account_type', _.bind(this._doValidateCheckType, this));
},
_doValidateCheckType: function(fields, errors, callback) {
//validate requirements
if (this.model.get('account_type') == 'Customer' && _.isEmpty(this.model.get('phone_office')))
{
errors['phone_office'] = errors['phone_office'] || {};
errors['phone_office'].required = true;
}
callback(null, fields, errors);
}
})
Don't forget to repair en rebuild!
The full documentation can be found here

Magento: Core sends welcome mail after customer is saved

I noticed the following bug:
When I add an address to a customer using the admin backend, or if I change an address and i save the customer, the Magento Costumer AccountController sends a standard email to the updated customer. The email template used is the template for the customer event "confirmed". This always happens when I update the customer.
Had someone the same problem or a solution for this? I can't understand why magento sends an email for this event...
Class: Mage_Adminhtml_CustomerController extends Mage_Adminhtml_Controller_Action
Methode: saveAction()
Solution: It's a core bug from older versions. The condition for sending a mail after saving a customer uses isset($sendPassToEmail). But if you notice, the sendPassToEmail variable is always set and has the values true or false. Because of the isset() the condition is always true and an email will be send every time a customer is saved.
...
$sendPassToEmail = false;
// force new customer active
if ($isNewCustomer) {
$customer->setPassword($data['account']['password']);
$customer->setForceConfirmed(true);
if ($customer->getPassword() == 'auto') {
$sendPassToEmail = true;
$customer->setPassword($customer->generatePassword());
}
}
Mage::dispatchEvent('adminhtml_customer_prepare_save', array(
'customer' => $customer,
'request' => $this->getRequest()
));
$customer->save();
// send welcome email
if ($customer->getWebsiteId() && (!empty($data['account']['sendemail']) || isset($sendPassToEmail))) {
$storeId = $customer->getSendemailStoreId();
if ($isNewCustomer) {
$customer->sendNewAccountEmail('registered', '', $storeId);
}
// confirm not confirmed customer
else if ((!$customer->getConfirmation())) {
$customer->sendNewAccountEmail('confirmed', '', $storeId);
}
}

Coupon Code For Paypal Express Checkout

I'm using Paypal Express Checkout system on my website. But I want to put a coupon (discount) code area. It will make a reduction if code is true. (Like GoDaddy.com's cart system)
Have you any idea, where should I start for this?
(I'm not using any eCommerce framework)
I know this is an old thread but wanted to put here my experience for others looking for the same thing, and maybe this did not apply then but it does apply now, at least on the sandbox meaning I have not tested this in a real transaction
When adding items that you send to paypal you basically send this
L_PAYMENTREQUEST_0_QTY0 = 1
L_PAYMENTREQUEST_0_AMT0 = 1.00
L_PAYMENTREQUEST_0_NAME0 = my item 0 name
L_PAYMENTREQUEST_0_NUMBER0 = myitem0id
Then we add another item
L_PAYMENTREQUEST_0_QTY1 = 1
L_PAYMENTREQUEST_0_AMT1 = 1.00
L_PAYMENTREQUEST_0_NAME1 = my item 1 name
L_PAYMENTREQUEST_0_NUMBER1 = myitem1id
And now we add the coupon
L_PAYMENTREQUEST_0_QTY2 = 1
L_PAYMENTREQUEST_0_AMT2 = -0.50
L_PAYMENTREQUEST_0_NAME2 = my coupon name
L_PAYMENTREQUEST_0_NUMBER2 = mycouponcode
And then we add the subtotal and total values
PAYMENTREQUEST_0_AMT = 1.50
AMT = 1.50
What I think paypal does is ads up all item totals so it would do for this order something like
1.00+1.00-0.50 = 1.50
Then compares it to your total amounts
if they match then it is a go, the customer sees this as an extra item, but obviously with the minus sign, this picture below is from a paypal sandbox express checkout transaction
One approach is to have a shopping cart on your site where the user can enter a promo code. Once they've entered their promo codes, and are ready to begin the checkout process, this is when you redirect them to the Express Checkout (where you send Paypal the final amount of your order, etc).
According to this post on Paypal forum, they do not have a feature to pass the discount details to the checkout process: https://www.x.com/thread/39681 ("With express checkout all discount calculations will need to be done on your site.")
How to calculate before sending price to paypal
1) Add a SEPARATE form for the promo code to your page:
<form method="GET">
<input type="text" name="promocode">
<input type="submit" value="Add Promo">
</form>
2) On the server side, check the code, update the page accordingly with new prices (e.g. re-build your select menu with new prices). Example with PHP:
<?
if(isset($_GET('promocode')) {
$prices = processPromo($_GET('promocode'));
}
else {
$prices = array(2000, 4000, 6000);
}
?>
If you don't have access to the server, you would have to do this with JavaScript I guess (i.e. have your promo-code and price hard-coded into the page)
To initiate express checkout on server side
Download PHP NVP SDK & examples from Paypal's website:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_download_sdks
<?php
require_once 'CallerService.php';
session_start();
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
/* Gather the information to make the final call to
finalize the PayPal payment. The variable nvpstr
holds the name value pairs
*/
$token =urlencode( $_SESSION['token']);
$paymentAmount =urlencode ($_SESSION['TotalAmount']);
$paymentType = urlencode($_SESSION['paymentType']);
$currCodeType = urlencode($_SESSION['currCodeType']);
$payerID = urlencode($_SESSION['payer_id']);
$serverName = urlencode($_SERVER['SERVER_NAME']);
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName ;
/* Make the call to PayPal to finalize payment
If an error occured, show the resulting errors
*/
$resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
if($ack != 'SUCCESS' && $ack != 'SUCCESSWITHWARNING'){
$_SESSION['reshash']=$resArray;
$location = "APIError.php";
header("Location: $location");
}
?>