I am make an M-Commerce application with the use of Xamarin.Forms in that user is able to checkout with payment integration and I have to use paypal method for checkout option and I am using .NET Standard project and project is also refer to the UWP. I check default paypal with example but I am not getting help.
I have new in payment integration method.
Can anyone look into this and suggest me what should I have to do in that?
You can use the Paypal Forms plugin for this:
In MainActivity(Android)/AppDelegate(iOS) after "Forms.Init()" call the Init method with your PayPal config value
global::Xamarin.Forms.Forms.Init ();
var config = new PayPalConfiguration(PayPalEnvironment.NoNetwork,"Your PayPal ID from
https://developer.paypal.com/developer/applications/")
{
//If you want to accept credit cards
AcceptCreditCards = true,
//Your business name
MerchantName = "Test Store",
//Your privacy policy Url
MerchantPrivacyPolicyUri = "https://www.example.com/privacy",
//Your user agreement Url
MerchantUserAgreementUri = "https://www.example.com/legal",
// OPTIONAL - ShippingAddressOption (Both, None, PayPal, Provided)
ShippingAddressOption = ShippingAddressOption.Both,
// OPTIONAL - Language: Default languege for PayPal Plug-In
Language = "es",
// OPTIONAL - PhoneCountryCode: Default phone country code for PayPal Plug-In
PhoneCountryCode = "52",
};
//iOS
CrossPayPalManager.Init(config);
//Android
CrossPayPalManager.Init(config, this);
...
You can find all the important API's on their Github itself.
In case of issues or anything of that sort feel free to revert
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 use laravel V6
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'token..',
'token..'
)
);
//dd($transaction);
$callbackUrl = url('/paypal/status');
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl($callbackUrl)
->setCancelUrl($callbackUrl);
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
try {
$payment->create($apiContext);
//dd($payment);
//dd($payment->getApprovalLink());
return redirect()->away($payment->getApprovalLink());
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
var_dump(json_decode($ex->getData()));
exit(1);
}
that's the controller, I followed the documentation enter link description here
but I get a 400 error enter link description here
The link it generates is as follows https://www.sandbox.paypal.com/webapps/hermes?flow=1-P&ulReturn=true&token=EC-88M93704JL735000S&country.x=US&locale.x=es_XC#/checkout/genericError?code=UEFZTUVOVF9ERU5JRUQ%3D
I can not understand why the error .. the client_id secret, are fine .. anyway it is directly in the controller and check that the sandbox account has a balance
For that ClientId/Secret it looks like the receiving account in the PayPal sandbox is from a country that cannot receive any payments, such as Bolivia. Create a new sandbox business account at https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts%2F for a different country that is able to receive PayPal payments, and then create a REST app for this new sandbox business account in the 'My Applications' side tab.
It looks like you are using an obsolete PHP integration, with the old v1 payments SDK
You should instead use the v2 Checkout-PHP-SDK, with two routes, one for 'Set Up Transaction' and one for 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
Instead of redirecting to the approval URL, use this front-end UI: https://developer.paypal.com/demo/checkout/#/pattern/server -- this gives an "in context" checkout experience that keeps your site loaded in the background, which provides a much superior modern web experience
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!!
we are using "Cash On Delivery" Payment method in magento 1.9.0 version
we support cash on delivery to only some zip/pin codes locations.
means we will accept cash only from some zip codes [means locations].
under "checkout" in "shipping address", customer will type his/her "zip code" .
using that zip code we have to validation.
means if we deliver the product to that zip code, than "COD" payment method should visible under "payment method"
otherwise "COD" should not visible.
if someone is unclear with above question , please refer following link :
How to restrict default COD in magento to certain zip codes only?
this is the question.
can anyone explain in detail about above solution....
or
also here in following link :
restrict default Cash on delivery for some zip/pin codes in magento 1.9.0
there is an option to enter list of zip codes that are restricted. but we need a solution for list of zip codes that allowed.
All you need is to edit the file /app/code/core/Mage/Payment/Model/Method/Cashondelivery.php
here you will get an answer :
public function isAvailable($quote = null)
{
if ($quote) {
// Here is the list of restricted Zip Codes
$restrictedZips = array(
'85001',
'87965'
);
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
$customerZip = $address->getPostcode();
if (in_array($customerZip, $restrictedZips)) {
return false;
}
}
return parent::isAvailable($quote);
}
restrict default Cash on delivery for some zip/pin codes in magento 1.9.0
here is free extension for cashondelivery restrict based on zipcode
http://www.magentocommerce.com/magento-connect/cashondelivery-based-on-zipcode.html
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.