How create Order works ( taxes and payment method )

Hello everyone,

I’ve created a code to create Payment and then create an order.

My issue his :

  • It does create the payment, and validate it (so no issue there) but the payment receipt display : payment method : offline, but it’s actually paid by stripe, and i want it to display : payment method : STRIPE
  • It does create the command in the backend section of commands. But it does not displays the taxes amount, all other lines are well displayed, but this line won’t. I did put 20 in the taxes infos, but it won’t display

Here is the code for those who want to take a look :

Backend :


import wixStoresBackend from 'wix-stores-backend';

export function createOrder(cartId, lineitems, total, shippingInfos, billinginfos, discount, customTextField, shippingCost) {
  let fullOrder = {
  "buyerLanguage": "FR",
  "cartId": (cartId).toString(),
  "currency": "EUR",
  "weightUnit": "KG",
  "billingInfo": billinginfos,
  "totals": {
   "subtotal": total*100/(100+20),
    "total": total + shippingCost,
    "shipping": shippingCost*100/(100+20),
  },
  "channelInfo": {
    "type": "WEB"
  },
  
  "paymentStatus": "PAID",
  "shippingInfo": shippingInfos,
  "lineItems": lineitems,
  "customField": customTextField,
  
  }

if(discount !== null) {

  fullOrder = {"buyerLanguage": "FR",
  "cartId": (cartId).toString(),
  "currency": "EUR",
  "weightUnit": "KG",
  "billingInfo": billinginfos,
  "totals": {
   "subtotal": total*100/(100+20),
    "total": total + shippingCost,
    "shipping": shippingCost*100/(100+20),
  },
  "channelInfo": {
    "type": "WEB"
  },
  
  "paymentStatus": "PAID",
  "shippingInfo": shippingInfos,
  "lineItems": lineitems,
  "customField": customTextField,
  "discount" : discount
  }
  if (total <= 0){
   fullOrder = {"buyerLanguage": "FR",
  "cartId": (cartId).toString(),
  "currency": "EUR",
  "weightUnit": "KG",
  "billingInfo": billinginfos,
  "totals": {
    "subtotal": total*100/(100+20),
    "total": total + shippingCost,
    "shipping": shippingCost*100/(100+20),
    
    
  },
  "channelInfo": {
    "type": "WEB"
  },
  
  "paymentStatus": "PAID",
  "shippingInfo": shippingInfos,
  "lineItems": lineitems,
  "customField": customTextField,
  "discount" : discount
  }
  }
}

  return wixStoresBackend.createOrder(fullOrder);
}

Front end :


export function pay_click(event) {
    cart.getCurrentCart().then((currentCart) => {
        if ($w("#addressInput1").valid === false) {
            $w("#addressbox").show()
        } else {
            $w("#addressbox").hide()
        }

        let billingInfos = {
            "address": {
                "formatted": $w("#addressInput1").value.formatted,
                "city": $w("#addressInput1").value.city,
                "country": $w("#addressInput1").value.country,
                "addressLine": $w("#addressInput1").value.streetAddress.number + ' ' + $w("#addressInput1").value.streetAddress.name,
                "postalCode": $w("#addressInput1").value.postalCode,
                "subdivision": $w("#addressInput1").value.subdivision
            },
            "lastName": $w("#input4").value,
            "firstName": $w("#input5").value,
            "email": $w("#input6").value,
            "phone": $w("#input7").value.toString(),

        }

        let today = new Date()
        today.setDate(new Date().getDate() + 3)
        let shippingInfo = {

            "deliveryOption": shippingType,

            "estimatedDeliveryTime": timeZone(today, "Europe/Paris"),
            "shipmentDetails": {
                "address": {
                    "formatted": $w("#addressInput2").value.formatted,
                    "city": $w("#addressInput2").value.city,
                    "country": $w("#addressInput2").value.country,
                    "addressLine": $w("#addressInput2").value.streetAddress.number + ' ' + $w("#addressInput2").value.streetAddress.name,
                    "postalCode": $w("#addressInput2").value.postalCode,
                    "subdivision": $w("#addressInput2").value.subdivision
                },
                "lastName": $w("#input4").value,
                "firstName": $w("#input5").value,
                "email": $w("#input6").value,
                "phone": $w("#input7").value.toString(),

                "shipmentPriceData": {
                    "price": Number($w('#dropdown1').value),
                    "taxIncludedInPrice": true
                }
            }
        }
        let shippingCost = Number($w("#dropdown1").value)

        let customTextField = {
            "title": "Remarque",
            "value": $w("#input3").value
        }
        if (currentCart.appliedCoupon !== null)
            discount = {
                "appliedCoupon": currentCart.appliedCoupon
            }

        else {
            discount = null
        }

        let lineItems = currentCart.lineItems.map(a => ({
            "lineItemType": "PHYSICAL",
            'productId': a.productId,
            "quantity": a.quantity,
            "name": a.name,
            "mediaItem": {
                "altText": a.name,
                "src": a.mediaItem.src
            },
            "priceData": { price: a.price, "taxIncludedInPrice": true },
            "tax": 20
        }))

        product = currentCart.lineItems.map(a => ({
                //  id: a.id,
                quantity: Number(a.quantity),
                name: a.name,
                //   'total': Number(a.totalPrice),
                price: Number(a.price),
                //   quantity: Number(a.quantity),

            })

        );
        let delivery = {
            //   id:150,
            quantity: 1,
            name: "Livraison",
            //   'total': Number(a.totalPrice),
            price: Number($w("#dropdown1").value),
        }

        product.push(delivery)
        let discounted;
        if (currentCart.appliedCoupon !== null) {
            discounted = Number(currentCart.appliedCoupon.discountValue.replace('€', ''))
        }
        let userinfo = {
            firstName: $w('#input5').value,
            lastName: $w('#input4').value,
            phone: $w('#input6').value,
            email: $w('#input6').value,
            countryCode: "FRA"

        }

        let total = Number($w("#total").text.replaceAll(',', '.').replaceAll(' €', ''))
        console.log(product, total, userinfo, discounted, shippingCost)
        createMyPayment(product, total, userinfo, discounted, shippingCost)
            .then((payment) => {
                wixPay.startPayment(payment.id)
                    .then((result) => {
                        if (result.status === "Successful") {
                            SendOrder(currentCart._id, lineItems, currentCart.totals.total, shippingInfo, billingInfos, discount, customTextField, shippingCost)
                            $w("#thanks").expand()
                            $w("#text1036").text = "Prix total de la commande : " + total + " €"
                            $w("#buyerInfos").collapse()
                        } else if (result.status === "Failed") {
                            // handle payment failure
                        } else if (result.status === "Pending") {
                            // handle payment pending
                        } else if (result.status === "Cancelled") {
                            // handle user closing payment panel
                        }

                    });
            });
    });

}

export function SendOrder(cartid, lineItems, totals, shippingInfo, billingInfos, discount, customTextField, shippingCost) {

    // console.log(currentCart._id, currentCart.lineItems, currentCart.totals.total, shippingInfo, billingInfos, discount, customTextField, shippingCost)
    createOrder(cartid, lineItems, totals, shippingInfo, billingInfos, discount, customTextField, shippingCost)

}

I don’t see any taxes information in your fullOrder.total that’s probably why taxes aren’t showing up.

SECURITY CONCERNS

I see several security issues in your code:

  1. The payment amount is sent from the frontend to createMyPayment: this means anyone could create a payment of 0.01€ instead of 1000€ and your system will process it.

  2. You build orders in the frontend with createOrder: that means anyone can “hack” your system to send a new order, even if they are not paid, or add items to their order after it was paid.

I highly recommend fixing those issues to avoid bad surprises.

Thanks for these two security concerns ! I’ll do what’s necessary !

And about how the pay method is displayed ?

Ok and the amount of taxe means the total taxes costs ? (Like 2 € for 10 € at 20 % taxes ?) or do i enter my taxes in percent ? (20%)

I believe this is the taxes amount not the percentage,

I believe it’s not possible yet to change the method of payment(checkout the documentation to confirm).

Good luck:)