public async Task <IActionResult> CreatePay(CreatePayRequestModel model)
        {
            // Set Return_URL And ClientRefId(Optional Value)
            model.ReturnUrl   = Return_URL;
            model.ClientRefId = "YOUR OPTIONAL VALUE";

            //Create A HttpClient and add Auth Header to it
            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Bearer", PayPing_Token);

            //Convert Request Model to Json String
            var data    = JsonConvert.SerializeObject(model);
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            //Send Create pay Request
            var response = await httpClient.PostAsync(PayPing_PayURL, content);

            //Check if we ran into an Issue
            response.EnsureSuccessStatusCode();

            //Get Response data
            string responseBody = await response.Content.ReadAsStringAsync();

            _logger.LogInformation(responseBody);

            //Convert Response data to Model and get PayCode
            var createPayResult = JsonConvert.DeserializeObject <CreatePayResponseModel>(responseBody);

            //Redirect User to GateWay with our PayCodeS
            return(Redirect($"{PayPing_PayURL}/gotoipg/{createPayResult.Code}"));
        }
示例#2
0
        /// <inheritdoc />
        public override async Task <IPaymentRequestResult> RequestAsync(Invoice invoice, CancellationToken cancellationToken = default)
        {
            if (invoice == null)
            {
                throw new ArgumentNullException(nameof(invoice));
            }

            var account = await GetAccountAsync(invoice).ConfigureAwaitFalse();

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", account.AccessToken);

            var body = new CreatePayRequestModel
            {
                Amount        = invoice.Amount,
                Description   = invoice.GetPayPingRequest()?.Description,
                PayerIdentity = invoice.GetPayPingRequest()?.Mobile,
                PayerName     = invoice.GetPayPingRequest()?.PayerName,
                ReturnUrl     = invoice.CallbackUrl,
                ClientRefId   = invoice.TrackingNumber.ToString()
            };

            //Send Create pay Request
            var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiRequestUrl, body, cancellationToken);

            //Check if we ran into an Issue
            response.EnsureSuccessStatusCode();

            //Get Response data
            var responseBody = await response.Content.ReadAsStringAsync();

            //Convert Response data to Model and get PayCode
            var createPayResult = JsonConvert.DeserializeObject <CreatePayResponseModel>(responseBody);

            //Redirect User to gateway with the Code

            var url = _pingGatewayOptions.PaymentPageUrl.ToggleStringAtEnd("/", shouldHave: true) + createPayResult.Code;

            return(PaymentRequestResult.SucceedWithRedirect(account.Name, _httpContextAccessor.HttpContext, url));
        }