I try a foreach in an object like this:
                            $data = '{
                                      "purchase_country": "'.$this->session->data['payment_address']['iso_code_2'].'",
                                              "purchase_currency": "'.$this->session->data['currency'].'",
                                              "locale": "'.$this->session->data['language'].'",
                                              "order_amount": '.$total.',
                                              "order_tax_amount":                       0,
                                              "order_lines": [{
                                                    '. foreach ($this->cart->getProducts() as $product) { .'
                                                    "reference": "19-402",
                                                    "name": "'.$product['name'].'",
                                                    "quantity": 1,
                                                    "unit_price": 210,
                                                    "tax_rate": 0,
                                                    "total_amount": 210,
                                                    "total_tax_amount": 0,
                                                    "image_url": "https://www.exampleobjects.com/logo.png",
                                                    "product_url": "https://www.estore.com/products/f2a8d7e34",
                                                '.}.'
                                              }]
                                             }';
But it seems, that the syntax isnt right. I got a Parse error: syntax error, unexpected 'foreach' (T_FOREACH)
Is a foreach possible in the object?
