From 4c87f471017177d2785b92b5be2f1c2510d5b819 Mon Sep 17 00:00:00 2001 From: Igor Goltsov Date: Fri, 3 Sep 2021 11:46:13 +0300 Subject: [PATCH] MPGS-430: Add a card details with Billing Address to the Payment request to allow AVS validation --- simplifycommerce.php | 58 +++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/simplifycommerce.php b/simplifycommerce.php index 4d80052..bdb029b 100644 --- a/simplifycommerce.php +++ b/simplifycommerce.php @@ -444,23 +444,7 @@ public function hookPaymentOptions($params) } } - // Create empty object by default - $cardholder_details = new stdClass; - - // Send the cardholder's details with the payment - if (isset($this->context->cart->id_address_invoice)) { - $invoice_address = new Address((int)$this->context->cart->id_address_invoice); - - if ($invoice_address->id_state) { - $state = new State((int)$invoice_address->id_state); - - if (Validate::isLoadedObject($state)) { - $invoice_address->state = $state->iso_code; - } - } - - $cardholder_details = $invoice_address; - } + $cardholder_details = $this->getCardholderDetails(); $currency = new Currency((int)($this->context->cart->id_currency)); @@ -723,6 +707,17 @@ public function processPayment() ); } + $cardholder_details = $this->getCardholderDetails(); + $country_iso = Country::getIsoById($cardholder_details->id_country); + $requestData['card'] = array( + 'addressCity' => $this->safe($cardholder_details->city), + 'addressCountry' => $country_iso, + 'addressLine1' => $this->safe($cardholder_details->address1), + 'addressLine2' => $this->safe($cardholder_details->address2), + 'addressState' => isset($cardholder_details->state) ? $this->safe($cardholder_details->state) : '', + 'addressZip' => $this->safe($cardholder_details->postcode), + ); + $txn_mode = Configuration::get('SIMPLIFY_TXN_MODE'); if ($txn_mode === self::TXN_MODE_PURCHASE) { @@ -832,6 +827,35 @@ public function processPayment() exit; } + /** + * @return Address|stdClass + * + * @throws PrestaShopDatabaseException + * @throws PrestaShopException + */ + private function getCardholderDetails() + { + // Create empty object by default + $cardholder_details = new stdClass; + + // Send the cardholder's details with the payment + if (isset($this->context->cart->id_address_invoice)) { + $invoice_address = new Address((int)$this->context->cart->id_address_invoice); + + if ($invoice_address->id_state) { + $state = new State((int)$invoice_address->id_state); + + if (Validate::isLoadedObject($state)) { + $invoice_address->state = $state->iso_code; + } + } + + $cardholder_details = $invoice_address; + } + + return $cardholder_details; + } + /** * Function to check if customer still exists in Simplify and if not to delete them from the DB. *