Help needed with syntax for repeating within js - PayPal Checkout Cart

I need to integrate with PayPal for cart payment because the client has used them for years and doesn’t want to change.

Their guides are horrid to work with. Information everywhere and it’s hard to work out what goes with what.

I’ve managed to get the core part working with some js embed code but I don’t know how to turn static product items into dynamic ones.

This is the portion of javascript I want to make dynamic by looping through the cart data.

    createOrder: function(data, actions) {
    return actions.order.create({
    "purchase_units": [{
    "amount": {
    "currency_code": "GBP",
    "value":dmx.parse('connWebsite.data.TotalToPay'),
    "breakdown": {
    "item_total": { /* Required when including the `items` array */
    "currency_code": "GBP",
    "value":dmx.parse('connWebsite.data.TotalToPay')
    }
    }
    },
    "items": [
    {
    "name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
    "description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
    "unit_amount": {
    "currency_code": "GBP",
    "value": "20"
    },
    "quantity": "1"
    },
    {
    "name": "Second Product Name", /* Shows within upper-right dropdown during payment approval */
    "description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
    "unit_amount": {
    "currency_code": "GBP",
    "value": "20"
    },
    "quantity": "1"
    },
    ]
    }]
    });
    },

I have First and Second products there which are added to the PayPal cart fine. But I want to create the repeat for the items array and then replace "name": "First Product Name" with "name":dmx.parse('connWebsite.data.ItemName').

I think I’m fine with it all apart from the actual repeater code.

Can anyone assist for me?

Community Page
Last updated: