Description
Which template or example
Describe the bug
There are significant problems with the warranty option examples provided for the Cart Transform API in both JavaScript and Rust implementations. These issues could lead to severe pricing errors and misuse of the API.
- Incorrect use of
presentmentCurrencyRate
(Critical):
Both JavaScript and Rust examples incorrectly apply presentmentCurrencyRate
to values that are already in the presentment currency. This results in drastically underpriced warranties.
JavaScript (line 76-86):
price: {
adjustment: {
fixedPricePerUnit: {
amount: (
cost.amountPerQuantity.amount *
(warrantyCostPercentage / 100) *
presentmentCurrencyRate
).toFixed(2),
},
},
},
Rust (line 59-69):
price: Some(ExpandedItemPriceAdjustment {
adjustment: ExpandedItemPriceAdjustmentValue::FixedPricePerUnit(
ExpandedItemFixedPricePerUnitAdjustment {
amount: Decimal(
line.cost.amount_per_quantity.amount.0
* (warranty_cost_percentage / 100.0)
* presentment_currency_rate,
),
},
),
}),
For example, if the store currency is JPY and the presentment currency is USD, this would lead to prices being reduced by a factor of about 150, potentially causing significant financial losses.
The correct implementation should not use presentmentCurrencyRate
at all, as the cost is already in the presentment currency.
- Incomplete implementation of the "expand" operation in JavaScript example:
The JavaScript example fails to include the original product in the expandedCartItems
array, which is a fundamental misunderstanding of how the "expand" operation should work. This makes the example unsuitable as a reference in the documentation.
JavaScript (line 72-88):
expandedCartItems: [
{
merchandiseId: warrantyVariantID.value,
quantity: 1,
price: {
adjustment: {
fixedPricePerUnit: {
amount: (
cost.amountPerQuantity.amount *
(warrantyCostPercentage / 100) *
presentmentCurrencyRate
).toFixed(2),
},
},
},
},
],
The correct implementation should include both the original product and the warranty in the expandedCartItems
array, as demonstrated in the Rust example.
These issues could lead to severe problems in real-world applications, including incorrect pricing and removal of original products from the cart. We kindly request that both examples be updated to correctly demonstrate the use of the Cart Transform API, ensuring they provide accurate guidance for developers implementing warranty options.