Skip to content

Commit

Permalink
Merge pull request #27 from payrexx/task/PP-12133
Browse files Browse the repository at this point in the history
task/PP-12133: Add Delivery Address Fields to Gateway Post Request
  • Loading branch information
ruban-kumar authored Jul 16, 2024
2 parents bde8fc0 + 4564b5a commit 63add7c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
29 changes: 25 additions & 4 deletions payrexx/controllers/front/payrexx.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,30 @@ public function postProcess()
}

$customer = $context->customer;
$address = new Address($cart->id_address_delivery);
$country = Country::getIsoById($address->id_country);

$invoiceAddress = new Address($cart->id_address_invoice);
$deliveryAddress = new Address($cart->id_address_delivery);

$billingAddress = [
'firstname' => $invoiceAddress->firstname,
'lastname' => $invoiceAddress->lastname,
'company' => $invoiceAddress->company,
'street' => $invoiceAddress->address1 . ' ' . $invoiceAddress->address2,
'postcode' => $invoiceAddress->postcode,
'city' => $invoiceAddress->city,
'country' => Country::getIsoById($invoiceAddress->id_country),
'phone' => $invoiceAddress->phone,
];

$shippingAddress = [
'firstname' => $deliveryAddress->firstname,
'lastname' => $deliveryAddress->lastname,
'company' => $deliveryAddress->company,
'street' => $deliveryAddress->address1 . ' ' . $deliveryAddress->address2,
'postcode' => $deliveryAddress->postcode,
'city' => $deliveryAddress->city,
'country' => Country::getIsoById($deliveryAddress->id_country),
];
$total = (float) $cart->getOrderTotal(true, Cart::BOTH);
$currency = $context->currency->iso_code;

Expand All @@ -68,8 +89,8 @@ public function postProcess()
$redirectUrls,
$cart,
$customer,
$address,
$country,
$billingAddress,
$shippingAddress,
$pm
);

Expand Down
22 changes: 15 additions & 7 deletions payrexx/src/Service/PayrexxApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function createPayrexxGateway(
array $redirectUrls,
$cart,
$customer,
$address,
string $country,
array $billingAddress,
array $shippingAddress,
array $pm
): ?Gateway {
$basket = [];
Expand Down Expand Up @@ -168,14 +168,22 @@ public function createPayrexxGateway(
$gateway->addField('forename', $customer->firstname);
$gateway->addField('surname', $customer->lastname);
$gateway->addField('company', $customer->company);
$gateway->addField('street', $address->address1);
$gateway->addField('postcode', $address->postcode);
$gateway->addField('place', $address->city);
$gateway->addField('country', $country);
$gateway->addField('phone', $address->phone);
$gateway->addField('street', $billingAddress['street']);
$gateway->addField('postcode', $billingAddress['postcode']);
$gateway->addField('place', $billingAddress['city']);
$gateway->addField('country', $billingAddress['country']);
$gateway->addField('phone', $billingAddress['phone']);
$gateway->addField('email', $customer->email);
$gateway->addField('custom_field_1', $cart->id, 'Prestashop ID');

$gateway->addField('delivery_forename', $shippingAddress['firstname']);
$gateway->addField('delivery_surname', $shippingAddress['lastname']);
$gateway->addField('delivery_company', $shippingAddress['company']);
$gateway->addField('delivery_street', $shippingAddress['street']);
$gateway->addField('delivery_postcode', $shippingAddress['postcode']);
$gateway->addField('delivery_place', $shippingAddress['city']);
$gateway->addField('delivery_country', $shippingAddress['country']);

try {
return $payrexx->create($gateway);
} catch (PayrexxException $e) {
Expand Down

0 comments on commit 63add7c

Please sign in to comment.