@@ -932,7 +932,11 @@ func (n *OpenBazaarNode) CheckoutBreakdown(data *repo.PurchaseData) (repo.Checko
932
932
if err != nil {
933
933
return emptyCheckoutBreakdown , err
934
934
}
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 )
936
940
if err != nil {
937
941
return emptyCheckoutBreakdown , err
938
942
}
@@ -1132,7 +1136,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
1132
1136
itemOriginAmt = itemOriginAmt .AddBigInt (totalSurcharge )
1133
1137
1134
1138
// apply coupon discounts
1135
- totalDiscount , err := GetTotalCouponCodeDiscount (nrl , item .CouponCodes )
1139
+ totalDiscount , err := GetTotalCouponCodeDiscount (nrl , item .CouponCodes , itemOriginAmt )
1136
1140
if err != nil {
1137
1141
return big .NewInt (0 ), err
1138
1142
}
@@ -1182,7 +1186,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
1182
1186
return total , nil
1183
1187
}
1184
1188
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 ) {
1186
1190
totalCouponCodeDiscount := big .NewInt (0 )
1187
1191
1188
1192
for _ , couponCode := range couponCodes {
@@ -1198,8 +1202,8 @@ func GetTotalCouponCodeDiscount(nrl *repo.Listing, couponCodes []string) (*big.I
1198
1202
totalCouponCodeDiscount .Sub (totalCouponCodeDiscount , disc )
1199
1203
} else if discountF := vendorCoupon .GetPercentDiscount (); discountF > 0 {
1200
1204
// 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 ) )
1203
1207
}
1204
1208
}
1205
1209
}
0 commit comments