Store shipping cost in the DTO

This commit is contained in:
Philipp Stracker 2024-08-13 19:31:51 +02:00
parent 611ab4c5a7
commit 3b92eaac81
No known key found for this signature in database
6 changed files with 30 additions and 7 deletions

View file

@ -37,6 +37,7 @@ class BaseHandler {
const data = result.data;
const transaction = new TransactionInfo(
data.total,
data.shipping_fee,
data.currency_code,
data.country_code,
true

View file

@ -17,6 +17,7 @@ class PayNowHandler extends BaseHandler {
const transaction = new TransactionInfo(
data.total,
data.shipping_fee,
data.currency_code,
data.country_code,
true

View file

@ -45,6 +45,7 @@ class SingleProductHandler extends BaseHandler {
).simulate( ( data ) => {
const transaction = new TransactionInfo(
data.total,
data.shipping_fee,
data.currency_code,
data.country_code,
true

View file

@ -3,19 +3,35 @@ export default class TransactionInfo {
#currency = '';
#isFinal = false;
#amount = 0;
#shippingFee = 0;
constructor( amount, currency, country, isFinal ) {
constructor( total, shippingFee, currency, country, isFinal ) {
this.#country = country;
this.#currency = currency;
this.#isFinal = isFinal;
this.amount = amount;
this.shippingFee = shippingFee;
this.amount = total - shippingFee;
}
set amount( newAmount ) {
this.#amount = Number( newAmount ) || 0;
}
set shippingFee( newCost ) {
this.#shippingFee = Number( newCost ) || 0;
}
set total( newTotal ) {
newTotal = Number( newTotal ) || 0;
if ( ! newTotal ) {
return;
}
this.#amount = newTotal - this.#shippingFee;
}
get currencyCode() {
return this.#currency;
}
@ -29,7 +45,9 @@ export default class TransactionInfo {
}
get totalPrice() {
return this.#amount.toFixed( 2 );
const total = this.#amount + this.#shippingFee;
return total.toFixed( 2 );
}
get dataObject() {