|
@@ -3,11 +3,12 @@
|
|
|
import Image from "next/image";
|
|
import Image from "next/image";
|
|
|
import { use } from "react";
|
|
import { use } from "react";
|
|
|
import { useForm, get } from "react-hook-form";
|
|
import { useForm, get } from "react-hook-form";
|
|
|
-import { useApolloClient } from "@apollo/client/react";
|
|
|
|
|
-import {CheckoutPaymentMethodsData} from "@/types/checkout/type";
|
|
|
|
|
|
|
+import {RepayOrderPaymentMethodsData} from "@/types/checkout/type";
|
|
|
import {GraphqlRequestResult} from "@/types/graphqlFetch/type";
|
|
import {GraphqlRequestResult} from "@/types/graphqlFetch/type";
|
|
|
-import {CREATE_PAYMENT_REPLAY} from "@/graphql";
|
|
|
|
|
|
|
+import { usePlaceOrder } from "@/utils/hooks/usePlaceOrder";
|
|
|
import PaypalButton from "../PaymentButton/PaypalButton";
|
|
import PaypalButton from "../PaymentButton/PaypalButton";
|
|
|
|
|
+import { overlayLoading } from "@/components/theme/ui/kernel/loading/api";
|
|
|
|
|
+import { confirmDialog } from "@/components/theme/ui/kernel/confirm/api";
|
|
|
|
|
|
|
|
interface PaymentReplayResult {
|
|
interface PaymentReplayResult {
|
|
|
orderId: string;
|
|
orderId: string;
|
|
@@ -20,14 +21,14 @@ export function PaymentMethodContinueTpPay({
|
|
|
defaultPaymentMethod,
|
|
defaultPaymentMethod,
|
|
|
orderId,
|
|
orderId,
|
|
|
}: {
|
|
}: {
|
|
|
- paymentMethodsDataPromise: Promise<GraphqlRequestResult<CheckoutPaymentMethodsData>>;
|
|
|
|
|
|
|
+ paymentMethodsDataPromise: Promise<GraphqlRequestResult<RepayOrderPaymentMethodsData>>;
|
|
|
defaultPaymentMethod: {method: string; methodTitle: string;}
|
|
defaultPaymentMethod: {method: string; methodTitle: string;}
|
|
|
orderId: string;
|
|
orderId: string;
|
|
|
}) {
|
|
}) {
|
|
|
const paymentMethodsData = use(paymentMethodsDataPromise);
|
|
const paymentMethodsData = use(paymentMethodsDataPromise);
|
|
|
- const paymentMethods = paymentMethodsData.data?.collectionPaymentMethods || [];
|
|
|
|
|
|
|
+ const paymentMethods = paymentMethodsData.data?.collectionRepayOrderPaymentMethods || [];
|
|
|
|
|
|
|
|
- const client = useApolloClient();
|
|
|
|
|
|
|
+ const { paymentRepay } = usePlaceOrder();
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
register,
|
|
register,
|
|
@@ -46,37 +47,38 @@ export function PaymentMethodContinueTpPay({
|
|
|
const selectedPaymentMethod = watch("paymentMethod");
|
|
const selectedPaymentMethod = watch("paymentMethod");
|
|
|
console.log('selectedPaymentMethod -------- ',selectedPaymentMethod);
|
|
console.log('selectedPaymentMethod -------- ',selectedPaymentMethod);
|
|
|
const handleCreateOrder = async () => {
|
|
const handleCreateOrder = async () => {
|
|
|
-
|
|
|
|
|
- return client.mutate({
|
|
|
|
|
- mutation: CREATE_PAYMENT_REPLAY,
|
|
|
|
|
- variables: {
|
|
|
|
|
- orderId: Number(orderId),
|
|
|
|
|
- paymentMethod: selectedPaymentMethod
|
|
|
|
|
- }
|
|
|
|
|
- }).then((res) => {
|
|
|
|
|
- const resData = res?.data?.createPaymentReplay?.paymentReplay ?? null;
|
|
|
|
|
- const result: PaymentReplayResult = {
|
|
|
|
|
- error: false,
|
|
|
|
|
- msg: '',
|
|
|
|
|
- orderId: resData?.gatewayOrderId ?? '',
|
|
|
|
|
- webOrderId: resData?.orderId ?? ''
|
|
|
|
|
- };
|
|
|
|
|
- return result;
|
|
|
|
|
- }).catch((err) => {
|
|
|
|
|
- const result: PaymentReplayResult = {
|
|
|
|
|
- error: true,
|
|
|
|
|
- msg: err.message,
|
|
|
|
|
- orderId: '',
|
|
|
|
|
- webOrderId: ''
|
|
|
|
|
- };
|
|
|
|
|
- // showToast(err.message,'danger');
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ return await paymentRepay({
|
|
|
|
|
+ orderId: Number(orderId),
|
|
|
|
|
+ paymentMethod: selectedPaymentMethod
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
};
|
|
};
|
|
|
const handleClickPay = async () => {
|
|
const handleClickPay = async () => {
|
|
|
return true;
|
|
return true;
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+ const airwallexRepay = async () => {
|
|
|
|
|
+ overlayLoading.start();
|
|
|
|
|
+ const res = await paymentRepay({
|
|
|
|
|
+ orderId: Number(orderId),
|
|
|
|
|
+ paymentMethod: selectedPaymentMethod,
|
|
|
|
|
+ paymentSuccessUrl: window.location.origin + '/paymentresult/result'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ console.log("airwallexPlaceOrder res ---- ", res);
|
|
|
|
|
+
|
|
|
|
|
+ if(!res.error && res.orderId) {
|
|
|
|
|
+ // 创建订单成功了,跳转支付页面
|
|
|
|
|
+ window.location.href = res.orderId;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //创建订单出错了
|
|
|
|
|
+ overlayLoading.stop();
|
|
|
|
|
+ confirmDialog({
|
|
|
|
|
+ title: "Warning",
|
|
|
|
|
+ content: res.msg + " Create order failed. Please try again.",
|
|
|
|
|
+ noCancel: true,
|
|
|
|
|
+ }).then(() => {});
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<form name="shipping method" className="w-full box-border px-4 mt-4">
|
|
<form name="shipping method" className="w-full box-border px-4 mt-4">
|
|
@@ -122,6 +124,7 @@ export function PaymentMethodContinueTpPay({
|
|
|
<p className="text-ly-12 text-[#666666] leading-4.75">
|
|
<p className="text-ly-12 text-[#666666] leading-4.75">
|
|
|
By providing your information, you agree to Wiggins'sPrivacy Policyand Terms of Use.
|
|
By providing your information, you agree to Wiggins'sPrivacy Policyand Terms of Use.
|
|
|
</p>
|
|
</p>
|
|
|
|
|
+
|
|
|
<div className="mt-6 w-full">
|
|
<div className="mt-6 w-full">
|
|
|
{selectedPaymentMethod === 'paypal_smart_button' &&
|
|
{selectedPaymentMethod === 'paypal_smart_button' &&
|
|
|
<PaypalButton
|
|
<PaypalButton
|
|
@@ -130,6 +133,13 @@ export function PaymentMethodContinueTpPay({
|
|
|
isRePay={true}
|
|
isRePay={true}
|
|
|
/>
|
|
/>
|
|
|
}
|
|
}
|
|
|
|
|
+ {(selectedPaymentMethod === 'awxklarna' || selectedPaymentMethod === 'awxafterpay') &&
|
|
|
|
|
+ <button className="flex items-center justify-center w-full h-12 bg-ly-green text-white rounded-3xl text-ly-16 font-bold"
|
|
|
|
|
+ onClick={airwallexRepay}
|
|
|
|
|
+ >
|
|
|
|
|
+ Place Order
|
|
|
|
|
+ </button>
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|