// Path: app/src/main/java/moltin/example_moltin/data/ShippingItem.java
// public class ShippingItem {
// 
//     private String itemSlug;
//     private String itemTitle;
//     private String itemPrice;
//     private String itemTotalPrice;
// 
//     public ShippingItem()
//     {
// 
//     }
// 
//     public ShippingItem(String itemSlug,
//                         String itemTitle,
//                         String itemPrice,
//                         String itemTotalPrice)
//     {
//         this.itemSlug=itemSlug;
//         this.itemTitle=itemTitle;
//         this.itemPrice=itemPrice;
//         this.itemTotalPrice=itemTotalPrice;
//     }
// 
//     public String getItemSlug() {
//         return itemSlug;
//     }
// 
//     public void setItemSlug(String itemSlug) {
//         this.itemSlug = itemSlug;
//     }
// 
//     public String getItemTitle() {
//         return itemTitle;
//     }
// 
//     public void setItemTitle(String itemTitle) {
//         this.itemTitle = itemTitle;
//     }
// 
//     public String getItemPrice() {
//         return itemPrice;
//     }
// 
//     public void setItemPrice(String itemPrice) {
//         this.itemPrice = itemPrice;
//     }
// 
//     public String getItemTotalPrice() {
//         return itemTotalPrice;
//     }
// 
//     public void setItemTotalPrice(String itemTotalPrice) {
//         this.itemTotalPrice = itemTotalPrice;
//     }
// }


import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import moltin.android_sdk.Moltin;
import moltin.android_sdk.utilities.Constants;
import moltin.example_moltin.R;
import moltin.example_moltin.data.ShippingItem;
            public void onClick(View view) {
                refreshShippings((int)view.getTag());
            }
        });

        layShippings.addView(myView);
    }

    private void checkoutOrder() {
        try {

            ((LinearLayout)findViewById(R.id.layLoading)).setVisibility(View.VISIBLE);
            moltin.cart.checkout(new Handler.Callback() {
                @Override
                public boolean handleMessage(Message msg) {

                    ((LinearLayout)findViewById(R.id.layLoading)).setVisibility(View.GONE);
                    JSONObject json=(JSONObject)msg.obj;

                    if (msg.what == Constants.RESULT_OK) {
                        try {
                            JSONArray jsonArrayMethods = json.getJSONObject("result").getJSONObject("shipping").getJSONArray("methods");

                            LinearLayout layShippings=(LinearLayout)findViewById(R.id.layShippings);

                            for(int i=0;i<jsonArrayMethods.length();i++)
                            {
                                String shipTitle=jsonArrayMethods.getJSONObject(i).getString("title");
                                String shipPrice=jsonArrayMethods.getJSONObject(i).getJSONObject("price").getJSONObject("data").getJSONObject("formatted").getString("with_tax");

// Path: app/src/main/java/moltin/example_moltin/data/ShippingItem.java
// public class ShippingItem {
// 
//     private String itemSlug;
//     private String itemTitle;
//     private String itemPrice;
//     private String itemTotalPrice;
// 
//     public ShippingItem()
//     {
// 
//     }
// 
//     public ShippingItem(String itemSlug,
//                         String itemTitle,
//                         String itemPrice,
//                         String itemTotalPrice)
//     {
//         this.itemSlug=itemSlug;
//         this.itemTitle=itemTitle;
//         this.itemPrice=itemPrice;
//         this.itemTotalPrice=itemTotalPrice;
//     }
// 
//     public String getItemSlug() {
//         return itemSlug;
//     }
// 
//     public void setItemSlug(String itemSlug) {
//         this.itemSlug = itemSlug;
//     }
// 
//     public String getItemTitle() {
//         return itemTitle;
//     }
// 
//     public void setItemTitle(String itemTitle) {
//         this.itemTitle = itemTitle;
//     }
// 
//     public String getItemPrice() {
//         return itemPrice;
//     }
// 
//     public void setItemPrice(String itemPrice) {
//         this.itemPrice = itemPrice;
//     }
// 
//     public String getItemTotalPrice() {
//         return itemTotalPrice;
//     }
// 
//     public void setItemTotalPrice(String itemTotalPrice) {
//         this.itemTotalPrice = itemTotalPrice;
//     }
// }


// Path: app/src/main/java/moltin/example_moltin/activities/ShippingMethodActivity.java
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import moltin.android_sdk.Moltin;
import moltin.android_sdk.utilities.Constants;
import moltin.example_moltin.R;
import moltin.example_moltin.data.ShippingItem;

            public void onClick(View view) {
                refreshShippings((int)view.getTag());
            }
        });

        layShippings.addView(myView);
    }

    private void checkoutOrder() {
        try {

            ((LinearLayout)findViewById(R.id.layLoading)).setVisibility(View.VISIBLE);
            moltin.cart.checkout(new Handler.Callback() {
                @Override
                public boolean handleMessage(Message msg) {

                    ((LinearLayout)findViewById(R.id.layLoading)).setVisibility(View.GONE);
                    JSONObject json=(JSONObject)msg.obj;

                    if (msg.what == Constants.RESULT_OK) {
                        try {
                            JSONArray jsonArrayMethods = json.getJSONObject("result").getJSONObject("shipping").getJSONArray("methods");

                            LinearLayout layShippings=(LinearLayout)findViewById(R.id.layShippings);

                            for(int i=0;i<jsonArrayMethods.length();i++)
                            {
                                String shipTitle=jsonArrayMethods.getJSONObject(i).getString("title");
                                String shipPrice=jsonArrayMethods.getJSONObject(i).getJSONObject("price").getJSONObject("data").getJSONObject("formatted").getString("with_tax");

                                shippingArray.add(new ShippingItem(jsonArrayMethods.getJSONObject(i).getString("slug"),shipTitle,shipPrice,jsonArrayMethods.getJSONObject(i).getJSONObject("totals").getJSONObject("post_discount").getJSONObject("formatted").getString("with_tax")));