package com.izouma.nineth.service;

import com.alibaba.fastjson.JSONObject;
import com.izouma.nineth.ApplicationTests;
import com.izouma.nineth.utils.DateTimeUtils;
import com.izouma.nineth.utils.SnowflakeIdWorker;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.time.LocalDateTime;

class SandPayServiceTest extends ApplicationTests {
    @Autowired
    private SandPayService    sandPayService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;

    @Test
    void requestAlipay() {
        JSONObject jsonObject = sandPayService.requestAlipayRaw(snowflakeIdWorker.nextId() + "",
                new BigDecimal("0.01"), "话费充值", "话费充值",
                DateTimeUtils.format(LocalDateTime.now().plusSeconds(3), "yyyyMMddHHmmss"), "");
        System.out.println(JSONObject.toJSONString(jsonObject, true));
    }

    @Test
    public void testQuery() {
        JSONObject jsonObject = sandPayService.query("964252580806926336");
    }

    @Test
    public void refund() {
        for (Integer integer : new Integer[]{6014609,
                6015032,
                6015680,
                6016164,
                6016401}) {
            sandPayService.refund(String.format("%012d", integer), new BigDecimal("1"));
        }
    }

    @Test
    public void queryTransfer() {
        sandPayService.queryTransfer("20220420151655", "966356799781339136");
    }
}