feat: add Airwallex payments and multi-currency support
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/payment"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
@@ -22,16 +23,17 @@ func calculateCreditedBalance(paymentAmount, multiplier float64) float64 {
|
||||
InexactFloat64()
|
||||
}
|
||||
|
||||
func calculateGatewayRefundAmount(orderAmount, payAmount, refundAmount float64) float64 {
|
||||
func calculateGatewayRefundAmount(orderAmount, payAmount, refundAmount float64, currency string) float64 {
|
||||
if orderAmount <= 0 || payAmount <= 0 || refundAmount <= 0 {
|
||||
return 0
|
||||
}
|
||||
if math.Abs(refundAmount-orderAmount) <= amountToleranceCNY {
|
||||
return decimal.NewFromFloat(payAmount).Round(2).InexactFloat64()
|
||||
fractionDigits := int32(payment.CurrencyMaxFractionDigits(currency))
|
||||
if math.Abs(refundAmount-orderAmount) <= paymentAmountToleranceForCurrency(currency) {
|
||||
return decimal.NewFromFloat(payAmount).Round(fractionDigits).InexactFloat64()
|
||||
}
|
||||
return decimal.NewFromFloat(payAmount).
|
||||
Mul(decimal.NewFromFloat(refundAmount)).
|
||||
Div(decimal.NewFromFloat(orderAmount)).
|
||||
Round(2).
|
||||
Round(fractionDigits).
|
||||
InexactFloat64()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user