how can i get list of payment methods with detail like code,title,method and? is it possible get available payment method in store with API ? i need list of all available payment method in magento store.
Here You can get all available payment methods in Magento
If for any reason you need to a get a list with all payment methods in Magento, you can do it easily by using the payment config class (app/code/core/Mage/Payment/Model/Config.php).
To get a list with all payments active and inactive:
$allAvailablePaymentMethods = Mage::getModel('payment/config')->getAllMethods();
To get a list with all active payment methods:
$allActivePaymentMethods = Mage::getModel('payment/config')->getActiveMethods();
To get a list with all credit cards that Magento supports:
$allCcTypes = Mage::getModel('payment/config')->getCcTypes();
get active payment methods
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$methods = array(array('value'=>'','label'=>Mage::helper('adminhtml')->__('–Please Select–')));
foreach ($payments as $paymentCode=>$paymentModel) {
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = array(
'label' => $paymentTitle,
'value' => $paymentCode,
);
}
return $methods;
yes you can get payment method using api. here is your solution
$client = new SoapClient('http://magentohost/api/soap/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'cart_payment.list', 'quoteId');
var_dump($result);
You can use also this helper:
$methods = Mage::helper('payment)->getStoreMethods($store = null, $quote = null)
So you can check for a single store and for a quote if you need.
Related
I'm facing one issue while splitting the order on checkout. I followed these code mentioned in the link:-
https://magento.stackexchange.com/questions/196669/magento-2-split-order-for-every-item
and
https://github.com/magestat/magento2-split-order
Both solution is working with offline payment like check/mo, Cash on delivery, po number etc. But its not working with credit card details. Always getting error regarding credit card details.
I'm putting some more information through code:-
I am stuck at a point to distribute order and assign payment method into it.
there are two scenario i'm getting:
if i assign payment method checkmo,Cash on delivery then order is splitted and everything is working fine with this.
But i need to order products using credit card and when i assign payment method code(credit card payment method is 'nmi_directpost') and also assign card details into quote and placed and order then its showing me error differently, Some time its shows credit card details is not valid, sometime page is redirected to cart page without any log/exception. Here is bunch of code i'm trying to do:-
public function aroundPlaceOrder(QuoteManagement $subject, callable $proceed, $cartId, $payment = null)
{
$currentQuote = $this->quoteRepository->getActive($cartId);
// Separate all items in quote into new quotes.
$quotes = $this->quoteHandler->normalizeQuotes($currentQuote);
if (empty($quotes)) {
return $result = array_values([($proceed($cartId, $payment))]);
}
// Collect list of data addresses.
$addresses = $this->quoteHandler->collectAddressesData($currentQuote);
/** #var \Magento\Sales\Api\Data\OrderInterface[] $orders */
$orders = [];
$orderIds = [];
foreach ($quotes as $items) {
/** #var \Magento\Quote\Model\Quote $split */
$split = $this->quoteFactory->create();
// Set all customer definition data.
$this->quoteHandler->setCustomerData($currentQuote, $split);
$this->toSaveQuote($split);
// Map quote items.
foreach ($items as $item) {
// Add item by item.
$item->setId(null);
$split->addItem($item);
}
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote 1st :-'. print_r($split->getData(),true));
$this->quoteHandler->populateQuote($quotes, $split, $items, $addresses, $payment);
// $split->getPayment()->setMethod('nmi_directpost');
// if ($payment) {
// $split->getPayment()->setQuote($split);
// $data = $payment->getData();
// $paymentDetails = $paymentCardDetails = '';
// $postData = file_get_contents("php://input");//Get all param
// $postData = (array)json_decode($postData);//Decode all json param
// foreach ($postData as $key => $value) {
// if ($key == 'paymentMethod') { //Get paymentMethod details
// $paymentDetails = (array)$value;
// foreach ($paymentDetails as $key1 => $paymentValue) {
// if ($key1 == 'additional_data') { //get paymentMethod Details like card details
// $paymentCardDetails = (array)$paymentValue;
// }
// }
// }
// }
// $split->setMethod('checkmo');
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('Paynet :-');
// $payment = $quotes->getPayment();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');
$quote = $cart->getQuote();
$paymentMethod = $quote->getPayment()->getMethod();
$payment = $this->checkoutSession->getQuote()->getData();
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('second Paynet :-');
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($paymentMethod,true));
// $split->setPayment($payment);
// $split->getPayment()->importData(array(
// 'method' =>'nmi_directpost',
// 'cc_type' =>'VI',
// 'cc_number' =>'4111111111111111',
// 'cc_exp_year' =>'2025',
// 'cc_exp_month'=>'10',
// ));
// }
// \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('original quote :-'. print_r($quotes->getData(),true));
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($split->getData(),true));
// \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info('new quote :-'. print_r($payment->getData(),true));
// Dispatch event as Magento standard once per each quote split.
$this->eventManager->dispatch(
'checkout_submit_before',
['quote' => $split]
);
$this->toSaveQuote($split);
$order = $subject->submit($split);
$orders[] = $order;
$orderIds[$order->getId()] = $order->getIncrementId();
if (null == $order) {
throw new LocalizedException(__('Please try to place the order again.'));
}
}
$currentQuote->setIsActive(false);
$this->toSaveQuote($currentQuote);
$this->quoteHandler->defineSessions($split, $order, $orderIds);
$this->eventManager->dispatch(
'checkout_submit_all_after',
['orders' => $orders, 'quote' => $currentQuote]
);
return $this->getOrderKeys($orderIds);
}
Please suggest how can we achieve order splitting with credit card payment.
Splitting payment across multiple credit cards like this is referred to as 'partial authorization'. (Note: This is a very different thing from 'partial invoicing' or 'partial capturing', terms you'll also see thrown around.)
Magento's default Authorize.Net gateway includes partial authorization functionality, you just have to enable it in the gateway settings. This works with both Community and Enterprise Edition. See official documentation on the setup and workflow here.
To my knowledge, this is the only payment method that supports it.
Note that the customer does not get to choose how much to charge to each card. Rather, if the card they enter does not have sufficient funds, they will be prompted to enter another one.
I've used standard yii2 functions for authorization. User sessions are stored in database.
How can I get the list of all authorized users in Yii2?
Use this code:
$sessions = (new Query())->select('*')->from('session')->where('expire > :now', [
':now' => time()
])->all();
foreach($sessions as $session) {
$sessionData = Yii::$app->session->readSession($session['id']);
$sessionUnserializedData = $this->unserialize_session($sessionData);
$userId = $sessionUnserializedData['__id'];
echo $userId;
}
unserialize_session method get from #phred gist.
I am using Magento API to get list product. But it have error
$proxy = new SoapClient($this->_url);
$sessionId = $proxy->login($this->_user, $this->_api);
$filters = array(
'sku' => array('like'=>'msj006%')
);
$result = $proxy->call($sessionId, 'product.list',$filters);
$resultEncode = json_encode($result);
But it giv error: Call to a member function getBackend() on boolean
What wrong here ?
It seems that you have customized core part of magneto Or any extension which is customizing product model can create this issue. You can check your core code located at "app/code/core/Mage/Eav/Model/Entity/Abstract.php"
public function isAttributeStatic($attribute)
{
$attrInstance = $this->getAttribute($attribute);
$attrBackendStatic = $attrInstance->getBackend()->isStatic();
return $attrInstance && $attrBackendStatic;
}
I am using magento 1.7 i am having 3 payment methods so i want to display one payment method randomly among the 3 payment methods on during customers checkout.waiting for a valuable suggestion.Thanks for reading.
Take a look # Disable payment options-only cash on delivery for particular product-magento or Cash On Delivery activated Admin Only ( Not Frontend enabled ) - Magento?
class MagePal_PaymentFilterByProduct_ActivePaymentMethod
{
//get all active (enable) payment method
public function toOptionArray()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
//Get current customer id
//remove method below after check if customer place order before or first order
foreach ($payments as $paymentCode=>$paymentModel) {
if($paymentModel->canUseCheckout() == 1){
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = array(
'label' => $paymentTitle,
'value' => $paymentCode,
);
}
}
return $methods;
}
}
I am using the omnipay setup here: https://github.com/adrianmacneil/omnipay to process a paypal express checkout.
The process works fine in that the user is redirected to paypal -> they login and choose to pay -> they get returned to my site at which point I capture the payment.
The problem I've got is that I need to capture the address they have entered into paypal as their billing / shipping address.
To send the user across to paypal I have the following:
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('XX-USERNAME_XX');
$gateway->setPassword('XX_PASSWORDXX');
$gateway->setSignature('XX_SIG_XX');
$gateway->setTestMode(true);
$response = $gateway->purchase(
array(
'cancelUrl'=>'http://www.XXX.co.uk/',
'returnUrl'=>'http://www.XXX.co.uk/paypalexpress_confirm',
'amount' => $totalamount,
'currency' => 'GBP'
)
)->send();
$response->redirect();
When the user is returned I have the following:
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('XX-USERNAME_XX');
$gateway->setPassword('XX_PASSWORDXX');
$gateway->setSignature('XX_SIG_XX');
$gateway->setTestMode(true);
$response = $gateway->completePurchase(
array(
'cancelUrl'=>'http://www.XXX.co.uk/',
'returnUrl'=>'http://www.XXX.co.uk/paypalexpress_confirm',
'amount' => $totalamount,
'currency' => 'GBP'
)
)->send();
echo $responsemsg=$response->getMessage();
echo '<br><br><br>';
$data = $response->getData();
print_r($data);
Nothing in the response message or the raw data contains the customer address.
Has anyone got this working as i'm struggling and it's the final step to complete the transaction.
For those who are trying to get this work it's as Adrian said.
You first do the normal omnipay paypal payment and then afterwards:
get the token you were given
preform a second call to paypal using the call getexpresscheckoutdetails method
this returns all the info you need
API info here: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails
The php script paypal provide to do it all for you:
https://cms.paypal.com/cms_content/ES/es_ES/files/developer/nvp_ECGetExpressCheckout_php.txt
omnipay\paypal\ProGateway.php add new function
public function fetchExpressCheckoutDetail(array $parameters = array())
{
return $this->createRequest('\Omnipay\PayPal\Message\FetchExpressCheckoutRequest', $parameters);
}
omnipay\paypal\src\Message add new file FetchExpressCheckoutRequest.php
namespace Omnipay\PayPal\Message;
class FetchExpressCheckoutRequest extends AbstractRequest
{
public function getData()
{
$data = $this->getBaseData('GetExpressCheckoutDetails');
$this->validate('transactionReference');
$data['TOKEN'] = $this->getTransactionReference();
$url = $this->getEndpoint()."?USER={$data['USER']}&PWD={$data['PWD']}&SIGNATURE={$data['SIGNATURE']}&METHOD=GetExpressCheckoutDetails&VERSION={$data['VERSION']}&TOKEN={$data['TOKEN']}";
parse_str (file_get_contents( $url ),$output);
$data = array_merge($data,$output);
return $data;
}
}
Usage:
$response = $gateway->completePurchase($params)->send();
$data = $response->getData();
$gateway->fetchExpressCheckoutDetail(array('transactionReference'=>$data['TOKEN']))->getData();
It will be not the best. But it works. :)
If it's not returned by the $response->getData() method, you might need to call PayPal's GetExpressCheckoutDetails API method to get the extra details about the transaction.
Omnipay doesn't support this out of the box, so you will probably need to copy and customize one of the existing requests to make a separate API call after you have confirmed payment.