Skip to content

Commit

Permalink
PON-556: Webhook orders shipping and billing address marked as defaul…
Browse files Browse the repository at this point in the history
…t… (#195)

* PON-556:Webhook orders shipping and billing address marked as default user address.

* fixed issue with rigistered user trying guest checkout and amount rounding issue

* amount rounding fix

* fixed billing addres not saved in quote
  • Loading branch information
ramth05 authored Sep 1, 2020
1 parent 87bef6b commit 88ff746
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
25 changes: 23 additions & 2 deletions Controller/Payment/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,29 @@ public function execute()
}
else
{
//setting updated billing address
if(empty($_POST['billing_address']) === false)
{
$billing_address = json_decode($_POST['billing_address'], 1);

$this->getQuote()->getBillingAddress()
->setFirstname($billing_address['firstname'])
->setLastname($billing_address['lastname'])
->setCountryId($billing_address['countryId'])
->setPostcode($billing_address['postcode'])
->setCity($billing_address['city'])
->setTelephone($billing_address['telephone'])
->setCompany($billing_address['company'])
->setStreet($billing_address['street'])
->setRegionId($billing_address['regionId'])
->setRegionCode($billing_address['regionCode'])
->setRegion($billing_address['region'])
->setSaveInAddressBook($billing_address['saveInAddressBook']);

$this->getQuote()->save();
}

$amount = (int) (round($this->getQuote()->getGrandTotal(), 2) * 100);
$amount = (int) (number_format($this->getQuote()->getGrandTotal() * 100, 0, ".", ""));

$payment_action = $this->config->getPaymentAction();

Expand Down Expand Up @@ -215,7 +236,7 @@ public function execute()
'order_id' => $receipt_id,
'amount' => $order->amount,
'quote_currency' => $this->getQuote()->getQuoteCurrencyCode(),
'quote_amount' => round($this->getQuote()->getGrandTotal(), 2),
'quote_amount' => number_format($this->getQuote()->getGrandTotal(), 2, ".", ""),
'maze_version' => $maze_version,
'module_version' => $module_version,
'is_hosted' => $merchantPreferences['is_hosted'],
Expand Down
32 changes: 9 additions & 23 deletions Controller/Payment/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected function orderPaid(array $post)
}

//validate amount before placing order
$quoteAmount = (int) (round($quote->getGrandTotal(), 2) * 100);
$quoteAmount = (int) (number_format($quote->getGrandTotal() * 100, 0, ".", ""));

if ($quoteAmount !== $post['payload']['payment']['entity']['amount'])
{
Expand Down Expand Up @@ -257,14 +257,11 @@ protected function orderPaid(array $post)

protected function getQuoteObject($post, $quoteId)
{
$email = $post['payload']['payment']['entity']['email'];

$quote = $this->quoteRepository->get($quoteId);


$firstName = $quote->getBillingAddress()->getFirstname() ?? 'null';
$lastName = $quote->getBillingAddress()->getLastname() ?? 'null';

$lastName = $quote->getBillingAddress()->getLastname() ?? 'null';
$email = $quote->getBillingAddress()->getEmail() ?? $post['payload']['payment']['entity']['email'];

$quote->getPayment()->setMethod(PaymentMethod::METHOD_CODE);

Expand All @@ -277,35 +274,24 @@ protected function getQuoteObject($post, $quoteId)
$customer->setWebsiteId($websiteId);

//get customer from quote , otherwise from payment email
if (empty($quote->getBillingAddress()->getEmail()) === false)
{
$customer = $customer->loadByEmail($quote->getBillingAddress()->getEmail());
}
else
{
$customer = $customer->loadByEmail($email);
}
$customer = $customer->loadByEmail($email);

//if quote billing address doesn't contains address, set it as customer default billing address
if ((empty($quote->getBillingAddress()->getFirstname()) === true) and (empty($customer->getEntityId()) === false))
if ((empty($quote->getBillingAddress()->getFirstname()) === true) and
(empty($customer->getEntityId()) === false))
{
$quote->getBillingAddress()->setCustomerAddressId($customer->getDefaultBillingAddress()['id']);
}

//If need to insert new customer
if (empty($customer->getEntityId()) === true)
//If need to insert new customer as guest
if ((empty($customer->getEntityId()) === true) or
(empty($quote->getBillingAddress()->getCustomerId()) === true))
{
$quote->setCustomerFirstname($firstName);
$quote->setCustomerLastname($lastName);
$quote->setCustomerEmail($email);
$quote->setCustomerIsGuest(true);
}
else
{
$customer = $this->customerRepository->getById($customer->getEntityId());

$quote->assignCustomer($customer);
}

$quote->setStore($store);

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "razorpay/magento",
"description": "Razorpay Magento 2.0 plugin for accepting payments.",
"version": "3.1.0",
"version": "3.1.1",
"require": {
"php": "~5.5.0|~5.6.0|^7.0",
"razorpay/razorpay": "2.*"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Razorpay_Magento" setup_version="3.1.0">
<module name="Razorpay_Magento" setup_version="3.1.1">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ define(
type: 'POST',
url: url.build('razorpay/payment/order?' + Math.random().toString(36).substring(10)),
data: {
email: this.user.email
email: this.user.email,
billing_address: JSON.stringify(quote.billingAddress())
},

/**
Expand Down

0 comments on commit 88ff746

Please sign in to comment.