|
|
@@ -8,6 +8,7 @@ use Webkul\Checkout\Facades\Cart;
|
|
|
use Webkul\Payment\Payment\Payment;
|
|
|
use Webkul\Sales\Models\Order;
|
|
|
use Webkul\Sales\Repositories\OrderRepository;
|
|
|
+use Webkul\Sales\Repositories\InvoiceRepository;
|
|
|
|
|
|
class Airwallex extends Payment
|
|
|
{
|
|
|
@@ -29,7 +30,10 @@ class Airwallex extends Payment
|
|
|
protected $captureIntentsUlr = 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/{id}/capture';
|
|
|
protected $paymentIntentsUlr = 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/';
|
|
|
|
|
|
- public function __construct()
|
|
|
+ public function __construct(
|
|
|
+ protected InvoiceRepository $invoiceRepository,
|
|
|
+ protected OrderRepository $orderRepository,
|
|
|
+ )
|
|
|
{
|
|
|
if ($this->getConfigData('mode') == 'live') {
|
|
|
$this->tokenUrl = 'https://api.airwallex.com/api/v1/authentication/login';
|
|
|
@@ -155,11 +159,11 @@ class Airwallex extends Payment
|
|
|
}
|
|
|
|
|
|
//成功修改状态
|
|
|
- public function payments_webhook_payment_intent_succeeded($orderId, $transactionId)
|
|
|
+ public function paymentSucceeded($orderId, $transactionId)
|
|
|
{
|
|
|
- $order = app(OrderRepository::class)->find($orderId);
|
|
|
+ $order = $this->orderRepository->find($orderId);
|
|
|
|
|
|
- if (!$order) {
|
|
|
+ if (!$order->id) {
|
|
|
return false;
|
|
|
}
|
|
|
if ($order->status != Order::STATUS_PENDING) {
|
|
|
@@ -173,28 +177,26 @@ class Airwallex extends Payment
|
|
|
$order->payment->additional = $additional;
|
|
|
$order->payment->save();
|
|
|
}
|
|
|
+ if ($order->canInvoice()) {
|
|
|
+ $this->invoiceRepository->create($this->prepareInvoiceData($order));
|
|
|
+ }
|
|
|
}
|
|
|
- //授权成功修改状态
|
|
|
- public function payments_webhook_payment_intent_requires_capture($orderId, $transactionId)
|
|
|
+ /**
|
|
|
+ * Prepares order's invoice data for creation.
|
|
|
+ */
|
|
|
+ protected function prepareInvoiceData($order): array
|
|
|
{
|
|
|
- $order = app(OrderRepository::class)->find($orderId);
|
|
|
+ $invoiceData = [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'invoice' => ['items' => []],
|
|
|
+ ];
|
|
|
|
|
|
- if (!$order) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- if ($order->status != Order::STATUS_PENDING) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $order->status = Order::STATUS_PROCESSING;
|
|
|
- $order->save();
|
|
|
- if ($order->payment) {
|
|
|
- $additional = $order->payment->additional;
|
|
|
- $additional['transaction_id'] = $transactionId;
|
|
|
- $order->payment->additional = $additional;
|
|
|
- $order->payment->save();
|
|
|
+ foreach ($order->items as $item) {
|
|
|
+ $invoiceData['invoice']['items'][$item->id] = $item->qty_to_invoice;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ return $invoiceData;
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取一个唯一的id
|
|
|
*/
|