title: laravel payment gross amount not match items price
body: <p>I have payment getaway (code below)</p>
  
  <pre><code>public function orderspayonline(Request $request, $id){
        error_log('masuk ke snap token dri ajax');
        $midtrans = new Midtrans;
  
        $item = Order::findOrFail($id);
        $buyer = $item-&gt;buyer_name;
        $address = $item-&gt;address;
        $city = $item-&gt;city;
        $postalcode = $item-&gt;postalcode;
        $province = $item-&gt;province;
        $email = $item-&gt;buyer_email;
        $phone = $item-&gt;phone;
        $carttotal = $item-&gt;price;
        $shipping = $item-&gt;shipping_cost;
  
        $transaction_details = array(
            'order_id'      =&gt; uniqid(),
            'gross_amount'  =&gt; $carttotal,
  // gross amount (total price buyer has to pay) is saved in order raw included shipping method like: (total price + weight * shipping cost).
  
        );
  
  
        // getting orders items detail
        $item_details = array();
        if(!empty($item-&gt;product_data)){ //product_data is my json column
          foreach($item-&gt;product_data as $item)
          {
            //calculate items price
            foreach($item['attributes'] as $itemsss)
            {
              $proweight = $itemsss['value'];
            }
            $pp = $item['quantity'] * $proweight * $shipping + $item['price'];
            //end calculation
              $item_details[] = array(
                  'id'        =&gt; $item['id'],
                  'price'     =&gt; $pp,
                  'quantity'  =&gt; $item['quantity'],
                  'name'      =&gt; $item['name'],
              );
          }
        }else{
          $item_details[] = array(
                  'id'        =&gt; $item-&gt;id,
                  'price'     =&gt; $item-&gt;price,
                  'quantity'  =&gt; $item-&gt;quantity,
                  'name'      =&gt; $item-&gt;product,
          );
        }
  
  // to be continued....
  </code></pre>
  
  <p>now as you see in my <code>//getting orders items detail</code> part i have 2 type of loop, <code>first one</code> will loop orders with json based details <code>second one</code> will loop orders which created manually for users by admins which data is not json.</p>
  
  <p>Previously I added <code>//calculate items price</code> as to get order weight and shipping price calculated with items price, in that case my gross amount would be same as my items price and everything works just fine without any error.</p>
  
  <h1>Issue</h1>
  
  <p>The problem occurs when I have more than one item in my json based orders then my customized loop would not work any more and i get error of <code>gross_amount</code> not same as <code>items_price</code>.</p>
  
  <p>any idea where should i change?</p>
  
  <h1>UPDATE</h1>
  
  <p>my json code of order with multiple item</p>
  
  <pre><code>{"4":{"id":4,"name":"product four","price":1500000,"quantity":2,"attributes":{"attr":{"name":"weight","value":"45"}},"conditions":[],"_conditions":[{"name":"Black","value":"10000"},{"name":"12 inch","value":"25000"}]},"1":{"id":1,"name":"product one","price":10000000,"quantity":"1","attributes":{"attr":{"name":"weight","value":"1"}},"conditions":[{}],"_conditions":[{"name":"Black","value":"10000"}]}}
  </code></pre>
  
  <p>my json code of order with one item</p>
  
  <pre><code>{"4":{"id":4,"name":"product four","price":1535000,"quantity":"1","attributes":{"attr":{"name":"weight","value":"45"}},"conditions":[{},{}],"_conditions":[{"name":"Black","value":"10000"},{"name":"12 inch","value":"25000"}]}}
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RHYlY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RHYlY.jpg" alt="screen1"></a></p>
  
  <h1>UPDATE 2</h1>
  
  <p><code>gross amount</code></p>
  
  <p>my <code>gross_amount</code> come from column named <code>price</code> value of that is sum of:</p>
  
  <pre><code>shipping cost * cart total weight + cart total amount
  </code></pre>
  
  <p>cart total amount might be included extra options added to items, or coupons reduced from items prices.</p>
  
  <p><strong>the trick i used is:</strong></p>
  
  <p>Getting that complete price (up) as my <code>gross amount</code> in order to get shipping price from customer as well, but the problem is my gateway company insist that my <code>gross_amount</code> and <code>items_price</code> be the exact same which doen't make seance to me because i have to get shipping cost as well.</p>
  
  <p>So the trick was manipulate with items price in order to raise them till sum of them riches my <code>gross_amount</code> which i did by adding:</p>
  
  <pre><code>$pp = $item['quantity'] * $proweight * $shipping + $item['price'];
  </code></pre>
  
  <blockquote>
    <p>now I realized that I didn't included those extra options/coupon codes
    values</p>
  </blockquote>
  
  <p><code>you can find them in _conditions in my sample codes above</code> in my <code>$pp</code> and that's why items price sum never riches to <code>gross_amount</code>.</p>
  
  <p>any idea how to add them as well?</p>