Send shipping address to Omnipay

This commit is contained in:
Hillel Coren 2017-12-08 14:53:10 +02:00
parent b8744db366
commit fcd5b308fa
2 changed files with 22 additions and 20 deletions

View File

@ -484,22 +484,23 @@ class BasePaymentDriver
} }
if (isset($input['address1'])) { if (isset($input['address1'])) {
// TODO use cache instead $hasShippingAddress = $this->accountGateway->show_shipping_address;
$country = Country::find($input['country_id']); $country = Utils::getFromCache($input['country_id'], 'countries');
$shippingCountry = $hasShippingAddress ? Utils::getFromCache($input['shipping_country_id'], 'countries') : $country;
$data = array_merge($data, [ $data = array_merge($data, [
'billingAddress1' => $input['address1'], 'billingAddress1' => trim($input['address1']),
'billingAddress2' => $input['address2'], 'billingAddress2' => trim($input['address2']),
'billingCity' => $input['city'], 'billingCity' => trim($input['city']),
'billingState' => $input['state'], 'billingState' => trim($input['state']),
'billingPostcode' => $input['postal_code'], 'billingPostcode' => trim($input['postal_code']),
'billingCountry' => $country->iso_3166_2, 'billingCountry' => $country->iso_3166_2,
'shippingAddress1' => $input['address1'], 'shippingAddress1' => $hasShippingAddress ? trim($this->input['shipping_address1']) : trim($input['address1']),
'shippingAddress2' => $input['address2'], 'shippingAddress2' => $hasShippingAddress ? trim($this->input['shipping_address2']) : trim($input['address2']),
'shippingCity' => $input['city'], 'shippingCity' => $hasShippingAddress ? trim($this->input['shipping_city']) : trim($input['city']),
'shippingState' => $input['state'], 'shippingState' => $hasShippingAddress ? trim($this->input['shipping_state']) : trim($input['state']),
'shippingPostcode' => $input['postal_code'], 'shippingPostcode' => $hasShippingAddress ? trim($this->input['shipping_postal_code']) : trim($input['postal_code']),
'shippingCountry' => $country->iso_3166_2, 'shippingCountry' => $hasShippingAddress ? $shippingCountry->iso_3166_2 : $country->iso_3166_2,
]); ]);
} }
@ -511,6 +512,7 @@ class BasePaymentDriver
$invoice = $this->invoice(); $invoice = $this->invoice();
$client = $this->client(); $client = $this->client();
$contact = $this->invitation->contact ?: $client->contacts()->first(); $contact = $this->invitation->contact ?: $client->contacts()->first();
$hasShippingAddress = $this->accountGateway->show_shipping_address;
return [ return [
'email' => $contact->email, 'email' => $contact->email,
@ -524,12 +526,12 @@ class BasePaymentDriver
'billingState' => $client->state, 'billingState' => $client->state,
'billingCountry' => $client->country ? $client->country->iso_3166_2 : '', 'billingCountry' => $client->country ? $client->country->iso_3166_2 : '',
'billingPhone' => $contact->phone, 'billingPhone' => $contact->phone,
'shippingAddress1' => $client->address1, 'shippingAddress1' => $client->shipping_address1 ? $client->shipping_address1 : $client->address1,
'shippingAddress2' => $client->address2, 'shippingAddress2' => $client->shipping_address1 ? $client->shipping_address1 : $client->address2,
'shippingCity' => $client->city, 'shippingCity' => $client->shipping_address1 ? $client->shipping_address1 : $client->city,
'shippingPostcode' => $client->postal_code, 'shippingPostcode' => $client->shipping_address1 ? $client->shipping_address1 : $client->postal_code,
'shippingState' => $client->state, 'shippingState' => $client->shipping_address1 ? $client->shipping_address1 : $client->state,
'shippingCountry' => $client->country ? $client->country->iso_3166_2 : '', 'shippingCountry' => $client->shipping_address1 ? ($client->shipping_country ? $client->shipping_country->iso_3166_2 : '') : ($client->country ? $client->country->iso_3166_2 : ''),
'shippingPhone' => $contact->phone, 'shippingPhone' => $contact->phone,
]; ];
} }

View File

@ -57,7 +57,7 @@
$('#shipToBillingAddress').click(function() { $('#shipToBillingAddress').click(function() {
var checked = $('#shipToBillingAddress').is(':checked'); var checked = $('#shipToBillingAddress').is(':checked');
$('.shipping-address input').prop('disabled', checked); $('.shipping-address input').prop('readonly', checked);
if (checked) { if (checked) {
copyBillingAddress(); copyBillingAddress();
} else { } else {