|
|
|
@ -77,6 +77,7 @@ const PaymentMethodItem = ({
|
|
|
|
|
convertedAmount, |
|
|
|
|
isConverting, |
|
|
|
|
isPaypalExpanded, |
|
|
|
|
isWaveExpanded, |
|
|
|
|
}: { |
|
|
|
|
option: PaymentOption; |
|
|
|
|
isSelected: boolean; |
|
|
|
@ -95,6 +96,7 @@ const PaymentMethodItem = ({
|
|
|
|
|
}[]; |
|
|
|
|
isConverting?: boolean; |
|
|
|
|
isPaypalExpanded?: boolean; |
|
|
|
|
isWaveExpanded?: boolean; |
|
|
|
|
}) => { |
|
|
|
|
const { t } = useTranslation(); |
|
|
|
|
const { user } = useUserStore(); |
|
|
|
@ -231,6 +233,60 @@ const PaymentMethodItem = ({
|
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
{/* Show Wave expanded view */} |
|
|
|
|
{isSelected && |
|
|
|
|
option.key === "wave" && |
|
|
|
|
isWaveExpanded && |
|
|
|
|
convertedAmount && |
|
|
|
|
convertedAmount.length > 0 && ( |
|
|
|
|
<View style={styles.paypalExpandedContainer}> |
|
|
|
|
<View style={styles.paypalCurrencyContainer}> |
|
|
|
|
<Text style={styles.currencyTitle}> |
|
|
|
|
{t("order.select_currency") || "Select Currency"} |
|
|
|
|
</Text> |
|
|
|
|
<View style={styles.currencyButtonsContainer}> |
|
|
|
|
<TouchableOpacity |
|
|
|
|
style={[ |
|
|
|
|
styles.currencyButton, |
|
|
|
|
styles.currencyButtonActive, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
<Text |
|
|
|
|
style={[ |
|
|
|
|
styles.currencyButtonText, |
|
|
|
|
styles.currencyButtonTextActive, |
|
|
|
|
]} |
|
|
|
|
> |
|
|
|
|
FCFA |
|
|
|
|
</Text> |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
{/* Display converted amount */} |
|
|
|
|
{isConverting ? ( |
|
|
|
|
<View style={styles.convertingContainer}> |
|
|
|
|
<ActivityIndicator size="small" color="#007efa" /> |
|
|
|
|
<Text style={styles.convertingText}> |
|
|
|
|
{t("order.converting") || "Converting..."} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
) : ( |
|
|
|
|
<View style={styles.convertedAmountContainer}> |
|
|
|
|
<Text style={styles.convertedAmountLabel}> |
|
|
|
|
{t("order.equivalent_amount") || "Equivalent Amount:"} |
|
|
|
|
</Text> |
|
|
|
|
<Text style={styles.convertedAmountValue}> |
|
|
|
|
{convertedAmount |
|
|
|
|
.reduce((acc, item) => acc + item.converted_amount, 0) |
|
|
|
|
.toFixed(2)}{" "} |
|
|
|
|
FCFA |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
)} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
)} |
|
|
|
|
</View> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
@ -275,15 +331,22 @@ export const PaymentMethod = () => {
|
|
|
|
|
}); |
|
|
|
|
const [totalAmount, setTotalAmount] = useState(121.97); |
|
|
|
|
const { logPaymentConfirm } = useBurialPointStore(); |
|
|
|
|
const [isWaveExpanded, setIsWaveExpanded] = useState(false); |
|
|
|
|
|
|
|
|
|
const toggleExpanded = () => { |
|
|
|
|
setIsPaypalExpanded(!isPaypalExpanded); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const onSelectPayment = (paymentId: string) => { |
|
|
|
|
if (paymentId === selectedPayment) { |
|
|
|
|
// If clicking on already selected paypal, toggle expansion
|
|
|
|
|
if (paymentId === "paypal") { |
|
|
|
|
setIsPaypalExpanded(!isPaypalExpanded); |
|
|
|
|
} |
|
|
|
|
// If clicking on already selected wave, toggle expansion
|
|
|
|
|
if (paymentId === "wave") { |
|
|
|
|
setIsWaveExpanded(!isWaveExpanded); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -292,11 +355,43 @@ export const PaymentMethod = () => {
|
|
|
|
|
// Auto-expand paypal when selecting it
|
|
|
|
|
if (paymentId === "paypal") { |
|
|
|
|
setIsPaypalExpanded(true); |
|
|
|
|
setIsWaveExpanded(false); |
|
|
|
|
setIsConverting(true); |
|
|
|
|
|
|
|
|
|
// Reset to USD when selecting PayPal
|
|
|
|
|
setSelectedCurrency("USD"); |
|
|
|
|
|
|
|
|
|
const data = { |
|
|
|
|
from_currency: user.currency, |
|
|
|
|
to_currency: "USD", |
|
|
|
|
amounts: { |
|
|
|
|
total_amount: previewOrder?.total_amount || 0, |
|
|
|
|
domestic_shipping_fee: createOrderData?.domestic_shipping_fee || 0, |
|
|
|
|
shipping_fee: createOrderData?.shipping_fee || 0, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
payApi |
|
|
|
|
.convertCurrency(data) |
|
|
|
|
.then((res) => { |
|
|
|
|
setConvertedAmount(res.converted_amounts_list); |
|
|
|
|
setIsConverting(false); |
|
|
|
|
}) |
|
|
|
|
.catch((error) => { |
|
|
|
|
console.error("Currency conversion failed:", error); |
|
|
|
|
setIsConverting(false); |
|
|
|
|
}); |
|
|
|
|
} else if (paymentId === "wave") { |
|
|
|
|
// Auto-expand wave when selecting it
|
|
|
|
|
setIsWaveExpanded(true); |
|
|
|
|
setIsPaypalExpanded(false); |
|
|
|
|
setIsConverting(true); |
|
|
|
|
|
|
|
|
|
setSelectedCurrency("FCFA"); |
|
|
|
|
|
|
|
|
|
const data = { |
|
|
|
|
from_currency: user.currency, |
|
|
|
|
to_currency: selectedCurrency, |
|
|
|
|
to_currency: "FCFA", |
|
|
|
|
amounts: { |
|
|
|
|
total_amount: previewOrder?.total_amount || 0, |
|
|
|
|
domestic_shipping_fee: createOrderData?.domestic_shipping_fee || 0, |
|
|
|
@ -315,10 +410,12 @@ export const PaymentMethod = () => {
|
|
|
|
|
setIsConverting(false); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// Close expansion for non-paypal options
|
|
|
|
|
// Close expansion for non-paypal and non-wave options
|
|
|
|
|
setIsPaypalExpanded(false); |
|
|
|
|
setIsWaveExpanded(false); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const onSelectCurrency = (currency: string) => { |
|
|
|
|
setSelectedCurrency(currency); |
|
|
|
|
setIsConverting(true); |
|
|
|
@ -342,6 +439,7 @@ export const PaymentMethod = () => {
|
|
|
|
|
setIsConverting(false); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getPaymentMethods = async () => { |
|
|
|
|
try { |
|
|
|
|
setLoading(true); |
|
|
|
@ -386,6 +484,7 @@ export const PaymentMethod = () => {
|
|
|
|
|
setLoading(false); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getPaymentIcon = (key: string): string => { |
|
|
|
|
switch (key) { |
|
|
|
|
case "Brainnel Pay(Mobile Money)": |
|
|
|
@ -400,9 +499,11 @@ export const PaymentMethod = () => {
|
|
|
|
|
return "💰"; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getPaymentMethods(); |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setLoading(true); |
|
|
|
|
if (route.params?.freight_forwarder_address_id) { |
|
|
|
@ -422,6 +523,7 @@ export const PaymentMethod = () => {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, [route.params?.freight_forwarder_address_id]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setCreateOrderData({ |
|
|
|
|
...orderData, |
|
|
|
@ -433,6 +535,7 @@ export const PaymentMethod = () => {
|
|
|
|
|
}); |
|
|
|
|
console.log("orderData", orderData); |
|
|
|
|
}, [orderData]); |
|
|
|
|
|
|
|
|
|
const handleSubmit = async () => { |
|
|
|
|
if (!selectedPayment) { |
|
|
|
|
Alert.alert(t("payment.select_payment")); |
|
|
|
@ -461,6 +564,11 @@ export const PaymentMethod = () => {
|
|
|
|
|
createOrderData.payment_method = selectedPayment; |
|
|
|
|
createOrderData.total_amount = |
|
|
|
|
selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
|
) |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
@ -474,6 +582,11 @@ export const PaymentMethod = () => {
|
|
|
|
|
); |
|
|
|
|
createOrderData.actual_amount = |
|
|
|
|
selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
|
) |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
@ -486,15 +599,22 @@ export const PaymentMethod = () => {
|
|
|
|
|
).toFixed(2) |
|
|
|
|
); |
|
|
|
|
createOrderData.currency = |
|
|
|
|
selectedPayment === "paypal" ? selectedCurrency : user.currency; |
|
|
|
|
selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency; |
|
|
|
|
createOrderData.domestic_shipping_fee = |
|
|
|
|
selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "domestic_shipping_fee" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "domestic_shipping_fee" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
|
: orderData?.domestic_shipping_fee; |
|
|
|
|
createOrderData.shipping_fee = |
|
|
|
|
selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.find((item) => item.item_key === "shipping_fee") |
|
|
|
|
?.converted_amount || 0 |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.find((item) => item.item_key === "shipping_fee") |
|
|
|
|
?.converted_amount || 0 |
|
|
|
|
: orderData?.shipping_fee; |
|
|
|
@ -505,6 +625,11 @@ export const PaymentMethod = () => {
|
|
|
|
|
offline_payment: currentTab === "offline" ? 0 : 1, |
|
|
|
|
all_price: |
|
|
|
|
selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
|
) |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
@ -520,7 +645,7 @@ export const PaymentMethod = () => {
|
|
|
|
|
(acc, item) => acc + item.quantity, |
|
|
|
|
0 |
|
|
|
|
), |
|
|
|
|
currency: selectedCurrency, |
|
|
|
|
currency: selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency, |
|
|
|
|
shipping_method: orderData?.transport_type || 0, |
|
|
|
|
shipping_price_outside: orderData?.shipping_fee || 0, |
|
|
|
|
shipping_price_within: orderData?.domestic_shipping_fee || 0, |
|
|
|
@ -566,9 +691,14 @@ export const PaymentMethod = () => {
|
|
|
|
|
data: res, |
|
|
|
|
payMethod: selectedPayment, |
|
|
|
|
currency: |
|
|
|
|
selectedPayment === "paypal" ? selectedCurrency : user.currency, |
|
|
|
|
selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency, |
|
|
|
|
amount: |
|
|
|
|
selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
|
) |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
@ -660,6 +790,7 @@ export const PaymentMethod = () => {
|
|
|
|
|
convertedAmount={convertedAmount} |
|
|
|
|
isConverting={isConverting} |
|
|
|
|
isPaypalExpanded={isPaypalExpanded} |
|
|
|
|
isWaveExpanded={isWaveExpanded} |
|
|
|
|
/> |
|
|
|
|
))} |
|
|
|
|
</View> |
|
|
|
@ -734,6 +865,10 @@ export const PaymentMethod = () => {
|
|
|
|
|
<View> |
|
|
|
|
<Text> |
|
|
|
|
{selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "total_amount" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "total_amount" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
@ -742,6 +877,8 @@ export const PaymentMethod = () => {
|
|
|
|
|
? selectedCurrency === "USD" |
|
|
|
|
? "USD" |
|
|
|
|
: "EUR" |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? "FCFA" |
|
|
|
|
: previewOrder?.currency} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
@ -751,6 +888,10 @@ export const PaymentMethod = () => {
|
|
|
|
|
<View> |
|
|
|
|
<Text> |
|
|
|
|
{selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "domestic_shipping_fee" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "domestic_shipping_fee" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
@ -759,6 +900,8 @@ export const PaymentMethod = () => {
|
|
|
|
|
? selectedCurrency === "USD" |
|
|
|
|
? "USD" |
|
|
|
|
: "EUR" |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? "FCFA" |
|
|
|
|
: previewOrder?.currency} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
@ -768,6 +911,10 @@ export const PaymentMethod = () => {
|
|
|
|
|
<View> |
|
|
|
|
<Text> |
|
|
|
|
{selectedPayment === "paypal" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "shipping_fee" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? convertedAmount.find( |
|
|
|
|
(item) => item.item_key === "shipping_fee" |
|
|
|
|
)?.converted_amount || 0 |
|
|
|
@ -776,6 +923,8 @@ export const PaymentMethod = () => {
|
|
|
|
|
? selectedCurrency === "USD" |
|
|
|
|
? "USD" |
|
|
|
|
: "EUR" |
|
|
|
|
: selectedPayment === "wave" |
|
|
|
|
? "FCFA" |
|
|
|
|
: previewOrder?.currency} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
@ -849,7 +998,42 @@ export const PaymentMethod = () => {
|
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
)} |
|
|
|
|
{selectedPayment !== "paypal" && ( |
|
|
|
|
{selectedPayment === "wave" && ( |
|
|
|
|
<View style={{ flexDirection: "row" }}> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: fontSize(18), |
|
|
|
|
fontWeight: "600", |
|
|
|
|
color: "#151515", |
|
|
|
|
textDecorationLine: "line-through", |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{( |
|
|
|
|
(previewOrder?.total_amount || 0) + |
|
|
|
|
(createOrderData?.domestic_shipping_fee || 0) + |
|
|
|
|
(createOrderData?.shipping_fee || 0) |
|
|
|
|
).toFixed(2)}{" "} |
|
|
|
|
{previewOrder?.currency} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: fontSize(18), |
|
|
|
|
fontWeight: "600", |
|
|
|
|
color: "#ff6000", |
|
|
|
|
marginLeft: 10, |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{convertedAmount |
|
|
|
|
.reduce( |
|
|
|
|
(acc, item) => acc + item.converted_amount, |
|
|
|
|
0 |
|
|
|
|
) |
|
|
|
|
.toFixed(2)}{" "} |
|
|
|
|
FCFA |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
)} |
|
|
|
|
{selectedPayment !== "paypal" && selectedPayment !== "wave" && ( |
|
|
|
|
<Text |
|
|
|
|
style={{ |
|
|
|
|
fontSize: fontSize(18), |
|
|
|
@ -873,11 +1057,15 @@ export const PaymentMethod = () => {
|
|
|
|
|
<TouchableOpacity |
|
|
|
|
style={[ |
|
|
|
|
styles.submitButton, |
|
|
|
|
(!selectedPayment || createLoading || isConverting) && |
|
|
|
|
(!selectedPayment || createLoading || isConverting ||
|
|
|
|
|
(selectedPayment === "paypal" && (convertedAmount.length === 0 || !convertedAmount.find(item => item.item_key === "total_amount"))) || |
|
|
|
|
(selectedPayment === "wave" && (convertedAmount.length === 0 || !convertedAmount.find(item => item.item_key === "total_amount")))) && |
|
|
|
|
styles.disabledButton, |
|
|
|
|
]} |
|
|
|
|
onPress={handleSubmit} |
|
|
|
|
disabled={!selectedPayment || createLoading || isConverting} |
|
|
|
|
disabled={!selectedPayment || createLoading || isConverting ||
|
|
|
|
|
(selectedPayment === "paypal" && (convertedAmount.length === 0 || !convertedAmount.find(item => item.item_key === "total_amount"))) || |
|
|
|
|
(selectedPayment === "wave" && (convertedAmount.length === 0 || !convertedAmount.find(item => item.item_key === "total_amount")))} |
|
|
|
|
> |
|
|
|
|
{createLoading ? ( |
|
|
|
|
<ActivityIndicator size="small" color="#fff" /> |
|
|
|
|