package com.younike.wxpay.service;

import com.younike.wxpay.params.Amount;
import com.younike.wxpay.params.RefundParams;
import com.younike.wxpay.params.TransactionParams;
import com.younike.wxpay.responses.TransactionResponse;
import com.younike.wxpay.service.impl.MerchantPayServiceImpl;
import com.younike.wxpay.service.impl.SupplierPayServiceImpl;
import org.junit.Before;
import org.junit.Test;


import static com.younike.wxpay.enums.TransactionType.APP;
import static com.younike.wxpay.enums.TransactionType.NATIVE;

public class WechatPayServiceTest {

    private MerchantPayServiceImpl merchantPayService;

    private SupplierPayServiceImpl supplierPayService;

    @Before
    public void setup() {
        merchantPayService = new MerchantPayServiceImpl();
        merchantPayService.setup();
        supplierPayService = new SupplierPayServiceImpl();
        supplierPayService.setup();
    }

    @Test
    public void merchantTransaction() {
        merchantPayService.transaction(NATIVE,
                TransactionParams.builder()
                        .description("保证金充值")
                        .out_trade_no("TEST-002")
                        .notify_url("https://home.uxianxin.com/api/member/order/payment/cb")
                        .amount(Amount.pay(2))
                        .build());
    }
    @Test
    public void merchantRefund() {
        merchantPayService.refund(
                RefundParams.builder()
                        .out_refund_no("TEST-001")
                        .out_trade_no("1fb3323dc01a49cbacbbb028c4823b6d")
                        .notify_url("https://home.uxianxin.com/api/member/order/refund/cb")
                        .amount(Amount.refund(1, 1))
                        .build());
    }

    @Test
    public void supplierTransaction() {
        TransactionResponse response = supplierPayService.transaction(APP,
                TransactionParams.builder()
                        .sub_mchid("1554473961")
                        .description("保证金充值")
                        .out_trade_no("TEST-008")
                        .notify_url("https://home.uxianxin.com/api/member/payment/cb")
                        .amount(Amount.pay(3))
                        .build());
        System.out.println(response);
    }

}
