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.
Related
I'm using the paypal API with Laravel, everything works fine. I just need to find the way to get the user email address and name.
$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId( $request->query('PayerID') );
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {
// I should get the info about the payer here
}
The v1/payments PayPal-PHP-SDK is deprecated, you should not use it for any new integration.
The current supported SDK is the v2/checkout/orders Checkout-PHP-SDK, which you should use instead.
You can try the srmklive package "v3" if you like, otherwise integrate directly.
You should be able to create two routes, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
The capture order response may have details about the payer and payment, if not use can do a 'Get' API call on the order ID for this information. Store it in your database before returning the JSON to the client code.
I want to enable the payment gateway for some products Only. On my website, I have cash on delivery & other payment gateways. Cash on delivery should be enabled for every product.
For that i created a attribute called payment gateway in product section . It is drop down attribute with yes & No as value . So this attribute now visible in product side . When we adding or editing a product we can see this attribute .
Please help on the following .
Now in checkout page i have to check the product in checkout have enabled the payment gateway . If yes then only i need to show the payment gateway , other wise it should be cash on delivery . How can i do this ?
Please help.
If you want to either enable or disable certain payment methods based on some criteria you can use the payment_method_is_active event.
In the payment_method_is_active event you have access to 3 parameters:
$observer->getEvent()->getData('method_instance), the payment method
$observer->getEvent()->getData('quote'), the quote being processed
$observer->getEvent()->getData('result'), a data object containing the result
In the result is_available is defined which is either true if the payment method should be enabled ("available") or false if it should be disabled.
With these 3 objects you can
Determine whether the payment method is the method you want to disable based on some criteria
Get the products in the quote and their attributes
Result to say whether the payment method should be enabled or not.
class DisablePaymentMethodBasedOnSomething implements ObserverInterface {
public function execute($observer) {
$event = $observer->getEvent();
$method = $event->getData('method_instance');
$quote = $event->getData('quote');
$result = $event->getData('result');
if (payment method is not cash on delivery) {
return;
}
if (quote does not contain products with gateway attribute) {
return;
}
$result->setData('...', false);
}
}
As you see I didn't fill in all the blanks, I hope the example will guide you in the right direction.
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);
I have configured a Magento 1.9 community store and all orders for which payment is made through Paypal or other payment methods (like cash on delivery), are showing up in backend.
However, when I checkout selecting Paypal as the gateway, cancel my order on the Paypal page and return to the website - my order is not showing in the admin. Isn't it supposed to show up as a cancelled order.
Since this was a store migrated from Shopify, we had to manually create about a 100 orders and change their dates in the database manually. Can this be a reason for this unexpected behaviour?
Edit 1: No order info is displayed in the grid even if the paypal window is closed instead of clicking in cancel as many answers are suggesting.
This is obvious because when you (as a customer) cancel an order in PayPal payment page it automatically destroys (unset) the order and the order quote before redirecting to shop - Not to be confused with the famous: Cancelled Order where as the name suggests is shown for the actual orders which have been actually done and then cancelled.
Depending on the PayPal method you are using this can be treated differently.
In standard PayPal you can find it in this controller:
\magento\app\code\core\Mage\Paypal\controllers\StandardController.php
when you cancel the order, cancelAction(), it first cancels the order:
public function cancelAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setQuoteId($session->getPaypalStandardQuoteId(true));
if ($session->getLastRealOrderId()) {
$order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
if ($order->getId()) {
$order->cancel()->save();
}
Mage::helper('paypal/checkout')->restoreQuote();
}
$this->_redirect('checkout/cart');
}
and then redirectAction() unset the quote before redirecting back to the cart page:
public function redirectAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setPaypalStandardQuoteId($session->getQuoteId());
$this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
$session->unsQuoteId();
$session->unsRedirectUrl();
}
On the other hand in PayPal Express, cancel operation is triggered in this controller:
\app\code\core\Mage\Paypal\Controller\Express\Abstract.php
public function cancelAction()
{
try {
$this->_initToken(false);
// TODO verify if this logic of order cancelation is deprecated
// if there is an order - cancel it
$orderId = $this->_getCheckoutSession()->getLastOrderId();
$order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false;
if ($order && $order->getId() && $order->getQuoteId() == $this->_getCheckoutSession()->getQuoteId()) {
$order->cancel()->save();
$this->_getCheckoutSession()
->unsLastQuoteId()
->unsLastSuccessQuoteId()
->unsLastOrderId()
->unsLastRealOrderId()
->addSuccess($this->__('Express Checkout and Order have been canceled.'))
;
} else {
$this->_getCheckoutSession()->addSuccess($this->__('Express Checkout has been canceled.'));
}
} catch (Mage_Core_Exception $e) {
$this->_getCheckoutSession()->addError($e->getMessage());
} catch (Exception $e) {
$this->_getCheckoutSession()->addError($this->__('Unable to cancel Express Checkout.'));
Mage::logException($e);
}
$this->_redirect('checkout/cart');
}
where it unset everything in the same place.
So in your case if you need to keep the quote (which I suppose is what you have been exploiting in your custom module) you have to change this behavior of PayPal module.
Please remember if you are going to do this do not modify the original core files, instead extend these classes in your custom module and apply your changes there.
When you cancel the order from Paypal page without completing the payment, it will redirect you back to your cart page. The order will not get placed.
If you close the page after paypal redirection, without completing the payment(note that you do not have to press cancel here) the order will get placed with pending payment status.
To verify whether paypal is working correctly or not, try to complete the payment process via paypal. If you are using it for testing purposes you can use the sandbox mode so that you won't get charged for your order.
Hope this helps!!
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)