示例#1
0
        public async Task <OApiCommonResult> RequestMpToken(CpDevInfo devInfo, CpRequestMpToken requestData)
        {
            var client  = new RestClient(API_ROOT);
            var request = new RestRequest("/oapi/manualPay/requestToken", Method.POST);

            request.AddHeader("devID", devInfo.DevID);
            request.AddHeader("devToken", devInfo.DevToken);

            if (string.IsNullOrWhiteSpace(requestData.sendSms))
            {
                requestData.sendSms = "N";
            }

            if (string.IsNullOrWhiteSpace(requestData.oneJustPayGoodName))
            {
                requestData.oneJustPayPrice = 0;
            }

            request.AddJsonBody(requestData);

            var response = await client.ExecuteAsync <OApiCommonResult>(request);

            // 성공
            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(response.Data);
            }

            var err = JsonConvert.DeserializeObject <CpResponseError>(response.Content);

            throw new CiderpayException(err);
        }
        private async void BtnExecute_OnClick(object sender, RoutedEventArgs e)
        {
            if (txtMemberID.Text.Length < 4)
            {
                MessageBox.Show("판매자 아이디를 입력해주세요");
                return;
            }

            if (txtCustomMobile.Text.Length < 10)
            {
                MessageBox.Show("고객 핸드폰 번호를 입력해주세요");
                return;
            }

            if (txtServiceName.Text.Length < 1)
            {
                MessageBox.Show("서비스명을 입력해주세요");
                return;
            }

            if (txtDevID.Text.Length < 1)
            {
                MessageBox.Show("개발사 아이디를 입력해주세요");
                return;
            }

            if (txtDevToken.Text.Length < 1)
            {
                MessageBox.Show("개발사 토큰을 입력해주세요");
                return;
            }

            var goodPrice = string.IsNullOrWhiteSpace(txtGoodPrice.Text) ? 0 : long.Parse(txtGoodPrice.Text);

            var request = new CpRequestMpToken()
            {
                memberID           = txtMemberID.Text,
                goodName           = txtServiceName.Text,
                customMobile       = txtCustomMobile.Text,
                customNo           = txtCustomNo.Text,
                reason             = txtReason.Text,
                oneJustPayGoodName = txtGoodName.Text,
                oneJustPayPrice    = goodPrice,
            };

            var devInfo = new CpDevInfo(txtDevID.Text, txtDevToken.Text);

            try
            {
                var result = await api.RequestMpToken(devInfo, request);

                if (result != null && result.success)
                {
                    txtResult.Text = "[성공] 결제창 : " + result.var1;
                }
                else
                {
                    txtResult.Text = "[실패] 요청에 실패했습니다.";
                }
            }
            catch (CiderpayException ex)
            {
                txtResult.Text = "[실패] - " + ex.Error.message;
                Debug.WriteLine(ex.Error);
            }
        }