Skip to content

Commit

Permalink
MPGS-430: Add a card details with Billing Address to the Payment requ…
Browse files Browse the repository at this point in the history
…est to allow AVS validation
  • Loading branch information
riversy committed Sep 3, 2021
1 parent 0b49196 commit 4c87f47
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions simplifycommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 4c87f47

Please sign in to comment.