how to restrict customer groups to use different paypal payment methods? - magento

NOTE :
i had tried this code which gets usergroup from backend .... and it works with checkmo and ccsave but doesn't work with paypal any method :(
can anyone tel me where i m wrong ?????

You should extend all those methods and implement your checks in following method instead
public function isAvailable($quote = null)

Related

How to use multiple payment gateways function in single controller in laravel 8?

I am using PayPal, Razor pay, Stripe payment gateways in my project. When select user one of them payment gateway it redirects to assigned controller function from there it redirects its particular controller. I want to write all the functions for payment gateways in single controller to cut off redirections for customer.
when user select payment gateway and submit the form it redirects to mentioned below controller function
if ($payment_mode->payment_gateway_name == "Paypal") {
return redirect()->route('paywithpaypal', $planId);
} else if ($payment_mode->payment_gateway_name == "Razorpay") {
return redirect()->route('paywithrazorpay', $planId);
} else if ($payment_mode->payment_gateway_name == "Stripe") {
return redirect()->route('paywithstripe', $planId);
} else if ($payment_mode->payment_gateway_name == "Bank Transfer") {
}
and in that controller all functions is defined.
Create Classes as below:
PaymentController
Seperate classes implementing RazorpayService, StripeService, BankTransferService apis
Factory Method to create class object of RazorpayService, StripeService, BankTransferService based on request parameters
PaymentController uses factory method to create object of appropriate service and calls appropriate method on this object using input parameters

Magento 2 - Can't get order data in custom controller for payment gateway integration

I am developing a module for a payment gateway.
I created module skeleton using module creator provided here.
I used redirection solution given in this.
I wrote custom controller where it is getting redirect.
Now in my custom controller I need to create data to post on the payment gateway and then will post that data to the payment gateway url.
Here I need order data which I and not getting in checkout session. I referred other extension they are using similar method but I am not getting any data.
protected function _getOrder()
{
if (!$this->_order) {
$incrementId = $this->_getCheckout()->getLastRealOrderId();
var_dump($incrementId);
$this->_orderFactory = $this->_objectManager->get('Magento\Sales\Model\OrderFactory');
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
}
return $this->_order;
}
protected function _getCheckout() {
return $this->_objectManager->get('Magento\Checkout\Model\Session');
}
you can use following method of load order.
$order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId);

Setting payment method to cart with Magento API

I'm using Magento API to create orders. My code fails when I want to add payment method to the cart :
$paymentMethod = array(
“method” => “paypal_standard”
);
$resultPaymentMethod = $proxy->call(
$sessionId,
“cart_payment.method”,
array(
$shoppingCartId,
$paymentMethod
)
);
I'm getting following error: Payment method is not allowed.
In admin section in System->Configuration->PayPal I have set Website Payments Standard but I didn't enabled any option in System->Configuration->Payment Methods cause there is none available for PayPal.
When I call:
$proxy->call($session, 'cart_payment.list')
method I get an empty array as there isn't any available payment method set. Does someone knows how and where paypal payment setting is saved in Magento ?
If I set another Payment method like "checkmo" then the order is created fine. The thing is that I only need to allow Paypal standard payment.
So my question is: How can I set payment method to PayPal to the cart so my order will be successfully created?
Thanks.
I have also facing this problem and find reason for it.
$method->canUseInternal() used in payment method api. When we use paypal or other redirect able methods in payment methos api in that case $method->canUseInternal() it getting false value.
So for this type situation we need to create own custom coding.
api function refreance:
protected function _canUsePaymentMethod($method, $quote){
if (!($method->isGateway() || $method->canUseInternal())) {
return false; }
if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) {
return false;
}
if (!$method->canUseForCurrency(Mage::app()->getStore($quote->getStoreId())->getBaseCurrencyCode())) {
return false;
}
To pay with Paypal you need your customer to be redirected to Paypal. Because of this fact, you may not be allowed to use this payment method using API. I recommend you to have look at isAvailable() of the payment method to customize this behaviour.

username availability in Yii framework using ajax

the scenario is i have a form in my Yii project that will take the username as input and sends the user a mail containing activation link if he has not received one. the form name is ResendActivationLinkForm which extends the CFormModel class. now at the submission time i wanna check if the username exists or not in the database using AJAX...How to use yii's own classes and functions to accomplish that?
well thanks for replies..but i got it in a simpler fashion.
i just added an array inside the form model ResendActivationLinkForm depicting my rule.. eg..
public function run(){
return array(
.....
.....
array('username','exist','className'=>'User'),
);
}
where username is my attributeName, exist is the validator alias and className is the Model class name whose attribute it should look for...
you can look at http://www.yiiframework.com/wiki/56/ for more details. :) Happy Coding. :)
If Usermodel is the model that has a username attribute, you can do something like this.
if(Usermodel::model()->findByAttributes(
array(),
'username = :inputtedUsername',
array(':inputtedUsername' => $_POST['username'],)))
{
//user found
}else{
//user not found
}
For more information about the various CActiveRecord methods check the website
I'd extend the form model with a custom validator, such as array('username','UsernameExistsValidator'). This validator class should extend CValidator and implement public function validateAttribute($object,$attribute) which can use $this->addError() to flag if the username is not available. See the source for other Yii validators if you need some more input on the bits in there.
The logic from the answer above would fit into validateAttribute,

Checking If Order is Being Edited By Admin?

My custom shipping module was failing because it couldn't get a sales quote when an order was being edited on the backend. This was the code I was using:
class Mymodule_Model_Mycarrier_Customrate
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$quote = Mage::getSingleton('checkout/type_onepage')->getQuote();
I need to get the current quote so I have access to the address information. I am making an API request that requires a street address.
Now if the order was being edited on the backend, this would obviously result in an error because the checkout singleton is no longer relevant. Instead I get the quote like this:
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
In my collectRates() method I need to determine which singleton to load. First I want to ask if this is the proper way of doing things, and also if my check for the backend is sufficient:
$quote = Mage::getSingleton('checkout/type_onepage')->getQuote();
// If admin is editing an order, find the quote by admin session.
if(Mage::getSingleton('admin/session')->isLoggedIn()){
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
}
I don't want this to potentially cause problems later. I also get the feeling that I may be using the collectRates() method wrong if I have to create a workaround like this.
The Mage_Shipping_Model_Rate_Request object already has access to the address via $request->getDestStreet(), etc...

Resources