mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Update shipping address from PayPal
This commit is contained in:
parent
7fbe213146
commit
ebedbf8809
@ -871,23 +871,32 @@ class BasePaymentDriver
|
|||||||
return $payment;
|
return $payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function updateClientFromOffsite($transRef, $paymentRef)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
public function completeOffsitePurchase($input)
|
public function completeOffsitePurchase($input)
|
||||||
{
|
{
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$ref = array_get($this->input, 'token') ?: $this->invitation->transaction_reference;
|
$transRef = array_get($this->input, 'token') ?: $this->invitation->transaction_reference;
|
||||||
|
|
||||||
if (method_exists($this->gateway(), 'completePurchase')) {
|
if (method_exists($this->gateway(), 'completePurchase')) {
|
||||||
$details = $this->paymentDetails();
|
$details = $this->paymentDetails();
|
||||||
$response = $this->gateway()->completePurchase($details)->send();
|
$response = $this->gateway()->completePurchase($details)->send();
|
||||||
$ref = $response->getTransactionReference() ?: $ref;
|
$paymentRef = $response->getTransactionReference() ?: $transRef;
|
||||||
|
|
||||||
if ($response->isCancelled()) {
|
if ($response->isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
} elseif (! $response->isSuccessful()) {
|
} elseif (! $response->isSuccessful()) {
|
||||||
throw new Exception($response->getMessage());
|
throw new Exception($response->getMessage());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$paymentRef = $transRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->updateClientFromOffsite($transRef, $paymentRef);
|
||||||
|
|
||||||
// check invoice still has balance
|
// check invoice still has balance
|
||||||
if (! floatval($this->invoice()->balance)) {
|
if (! floatval($this->invoice()->balance)) {
|
||||||
throw new Exception(trans('texts.payment_error_code', ['code' => 'NB']));
|
throw new Exception(trans('texts.payment_error_code', ['code' => 'NB']));
|
||||||
@ -895,12 +904,12 @@ class BasePaymentDriver
|
|||||||
|
|
||||||
// check this isn't a duplicate transaction reference
|
// check this isn't a duplicate transaction reference
|
||||||
if (Payment::whereAccountId($this->invitation->account_id)
|
if (Payment::whereAccountId($this->invitation->account_id)
|
||||||
->whereTransactionReference($ref)
|
->whereTransactionReference($paymentRef)
|
||||||
->first()) {
|
->first()) {
|
||||||
throw new Exception(trans('texts.payment_error_code', ['code' => 'DT']));
|
throw new Exception(trans('texts.payment_error_code', ['code' => 'DT']));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->createPayment($ref);
|
return $this->createPayment($paymentRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tokenLinks()
|
public function tokenLinks()
|
||||||
|
@ -41,4 +41,29 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function updateClientFromOffsite($transRef, $paymentRef)
|
||||||
|
{
|
||||||
|
$response = $this->gateway()->fetchCheckout([
|
||||||
|
'token' => $transRef
|
||||||
|
])->send();
|
||||||
|
|
||||||
|
$data = $response->getData();
|
||||||
|
$client = $this->client();
|
||||||
|
|
||||||
|
$client->shipping_address1 = trim($data['SHIPTOSTREET']);
|
||||||
|
$client->shipping_address2 = '';
|
||||||
|
$client->shipping_city = trim($data['SHIPTOCITY']);
|
||||||
|
$client->shipping_state = trim($data['SHIPTOSTATE']);
|
||||||
|
$client->shipping_postal_code = trim($data['SHIPTOZIP']);
|
||||||
|
|
||||||
|
if ($country = cache('countries')->filter(function ($item) use ($data) {
|
||||||
|
return strtolower($item->iso_3166_2) == strtolower(trim($data['SHIPTOCOUNTRYCODE']));
|
||||||
|
})->first()) {
|
||||||
|
$client->shipping_country_id = $country->id;
|
||||||
|
} else {
|
||||||
|
$client->shipping_country_id = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user