|
|
@@ -144,19 +144,15 @@ class Afterpay extends Payment
|
|
|
'verify' => false
|
|
|
]);
|
|
|
$resultObject = json_decode($response->getBody()->getContents());
|
|
|
- if ($resultObject->token == 'APPROVED') {
|
|
|
- return true;
|
|
|
+ if ($resultObject->status == 'APPROVED') {
|
|
|
+ return ['transaction_id' => $resultObject->token, 'amount' => $resultObject->events[0]->amount->amount];
|
|
|
} else {
|
|
|
- return false;
|
|
|
+ return [];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function paymentsSuccess($orderId, $transactionId)
|
|
|
+ public function captureAndVerify($order, $transactionId)
|
|
|
{
|
|
|
- $order = app(OrderRepository::class)->find($orderId);
|
|
|
- if (!$order->id) {
|
|
|
- return new \Exception('order is empty');
|
|
|
- }
|
|
|
if ($order->status != Order::STATUS_PENDING) {
|
|
|
return new \Exception('order status is error');
|
|
|
}
|
|
|
@@ -166,17 +162,7 @@ class Afterpay extends Payment
|
|
|
if ($transactionId != $token) {
|
|
|
return new \Exception('order token is error');
|
|
|
}
|
|
|
- if (!$this->capture($token)) {
|
|
|
- return new \Exception('order capture fail');
|
|
|
- }
|
|
|
- $order->status = Order::STATUS_PROCESSING;
|
|
|
- $order->save();
|
|
|
- $additional['transaction_id'] = $transactionId;
|
|
|
- if ($order->payment) {
|
|
|
- $order->payment->additional = $additional;
|
|
|
- $order->payment->save();
|
|
|
- }
|
|
|
- return true;
|
|
|
+ return $this->capture($token);
|
|
|
}
|
|
|
|
|
|
public function getBaseUlr()
|
|
|
@@ -208,12 +194,8 @@ class Afterpay extends Payment
|
|
|
if (! parent::isAvailable()) {
|
|
|
return false;
|
|
|
}
|
|
|
- $cart = Cart::getCart();
|
|
|
- if (! $cart) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- if ($cart->billing_address) {
|
|
|
- $billingCountry = $cart->billing_address->country;
|
|
|
+ $info = $this->getOrder() ?: Cart::getCart();
|
|
|
+ if ($info && $billingCountry = $info->billing_address->country ?? false) {
|
|
|
$allowedCountries = ['AU', 'CA', 'NZ', 'GB', 'US'];
|
|
|
return in_array($billingCountry, $allowedCountries);
|
|
|
}
|