Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 008ecc0

Browse files
committed
Fix test errors
1 parent c11f040 commit 008ecc0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

core/order.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,11 @@ func (n *OpenBazaarNode) CheckoutBreakdown(data *repo.PurchaseData) (repo.Checko
932932
if err != nil {
933933
return emptyCheckoutBreakdown, err
934934
}
935-
couponDiscount, err := GetTotalCouponCodeDiscount(nrl, firstItem.CouponCodes)
935+
cv := &repo.CurrencyValue{
936+
Amount: totalSurcharge.Add(totalSurcharge, itemOriginAmt.Amount),
937+
Currency: listingCurDef,
938+
}
939+
couponDiscount, err := GetTotalCouponCodeDiscount(nrl, firstItem.CouponCodes, cv)
936940
if err != nil {
937941
return emptyCheckoutBreakdown, err
938942
}
@@ -1132,7 +1136,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
11321136
itemOriginAmt = itemOriginAmt.AddBigInt(totalSurcharge)
11331137

11341138
// apply coupon discounts
1135-
totalDiscount, err := GetTotalCouponCodeDiscount(nrl, item.CouponCodes)
1139+
totalDiscount, err := GetTotalCouponCodeDiscount(nrl, item.CouponCodes, itemOriginAmt)
11361140
if err != nil {
11371141
return big.NewInt(0), err
11381142
}
@@ -1182,7 +1186,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
11821186
return total, nil
11831187
}
11841188

1185-
func GetTotalCouponCodeDiscount(nrl *repo.Listing, couponCodes []string) (*big.Int, error) {
1189+
func GetTotalCouponCodeDiscount(nrl *repo.Listing, couponCodes []string, itemAmount *repo.CurrencyValue) (*big.Int, error) {
11861190
totalCouponCodeDiscount := big.NewInt(0)
11871191

11881192
for _, couponCode := range couponCodes {
@@ -1198,8 +1202,8 @@ func GetTotalCouponCodeDiscount(nrl *repo.Listing, couponCodes []string) (*big.I
11981202
totalCouponCodeDiscount.Sub(totalCouponCodeDiscount, disc)
11991203
} else if discountF := vendorCoupon.GetPercentDiscount(); discountF > 0 {
12001204
// apply percentage discount
1201-
disc, _ := toHundredths(-discountF).Int(nil)
1202-
totalCouponCodeDiscount.Add(totalCouponCodeDiscount, disc)
1205+
disc := itemAmount.AddBigFloatProduct(toHundredths(-discountF))
1206+
totalCouponCodeDiscount.Sub(totalCouponCodeDiscount, new(big.Int).Sub(itemAmount.Amount, disc.Amount))
12031207
}
12041208
}
12051209
}

0 commit comments

Comments
 (0)