package com.diaoyun.zion;

import com.diaoyun.zion.master.util.JsoupUtil;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.CurType;
import com.egzosn.pay.common.bean.MethodType;
import com.egzosn.pay.common.bean.PayOrder;
import com.egzosn.pay.common.http.HttpConfigStorage;
import com.egzosn.pay.paypal.api.PayPalConfigStorage;
import com.egzosn.pay.paypal.api.PayPalPayService;
import com.egzosn.pay.paypal.bean.PayPalTransactionType;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.paypal.api.payments.Links;
import net.sf.json.JSONObject;


import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 *
 *
 * 微信
 * @author egan
 * @email egzosn@gmail.com
 * @date 2017/8/18
 */
public class PayTest {

    public static void main(String[] args) {

        PayPalConfigStorage storage = new PayPalConfigStorage();
        storage.setClientID("AW7u5JVLhzA7_0EznoZ7uKHFzz1_nACOtt6k9oEpbisGUy3nqjjb3L-MmBFnD3YDuMSapcXpfSiYWtiB");
        storage.setClientSecret("EIyDryMDyM0BDWp2mtuGFdSU2WOkWtmSuGGaRnUiIom7kxuM7JhuSFfETbC8X4e9E_ZbMX4zg4jHA1lV");
        storage.setTest(true);
        //发起付款后的页面转跳地址
        storage.setReturnUrl("http://localhost:8083/zion/paypal/success?orderId=d56afd2ab3134dee87b6ba7dc88c4c8c");
        //取消按钮转跳地址,这里用异步通知地址的兼容的做法
        storage.setNotifyUrl("http://localhost:8083/zion/paypal/cancel");
        HttpConfigStorage httpConfigStorage = new HttpConfigStorage();

        PayService service = new PayPalPayService(storage);
        BigDecimal price = new BigDecimal("500");
        PayOrder order = new PayOrder("Order_payment:", "Order payment", price, UUID.randomUUID().toString().replace("-", ""), PayPalTransactionType.sale);
        Map orderInfo = service.orderInfo(order);
//        String payId =(String) orderInfo.get("id");
//        System.out.println("orderInfo====>>>"+orderInfo);
//        System.out.println("links====>>>"+orderInfo.get("links"));
//        String request = service.buildRequest(orderInfo, MethodType.POST);
//        System.out.println(request);
//        Set set = orderInfo.entrySet();
//        Iterator iterator = set.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
        System.out.println(orderInfo.get("links"));
        Map<String, String> orderHref = JsoupUtil.getOrderHref(orderInfo.toString());
        System.out.println(orderHref.get("approval_url"));

    }
}
