public async Task <IActionResult> ConfirmPay(PPVerifyPayHookModel model)
        {
            //Create A HttpClient and add Auth Header to it
            var httpClient = new HttpClient();

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

            var verify_model = new VerifyPayRequestModel()
            {
                Amount = 1000,
                RefId  = model.RefId
            };

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

            //Send Verify pay Request
            var response = await httpClient.PostAsync(PayPing_PayURL + "/verify", 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 our Payment Details
            var paymentDetails = JsonConvert.DeserializeObject <VerifyPayResponseModel>(responseBody);

            //Show Confirm Page
            return(View());
        }
Exemple #2
0
        /// <inheritdoc />
        public override async Task <IPaymentVerifyResult> VerifyAsync(InvoiceContext context, CancellationToken cancellationToken = default)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var account = await GetAccountAsync(context.Payment).ConfigureAwaitFalse();

            var request = _httpContextAccessor.HttpContext.Request;

            var refId = await request.TryGetParamAsync("refid", cancellationToken);

            var amount = await request.TryGetParamAsAsync <long>("amount", cancellationToken);

            var clientRefId = await request.TryGetParamAsync("clientrefid", cancellationToken);

            var isValid = true;
            var message = "";

            if (!refId.Exists)
            {
                isValid  = false;
                message += "RefId isn't received.";
            }

            if (!amount.Exists)
            {
                isValid  = false;
                message += "Amount isn't received.";
            }

            if (!clientRefId.Exists)
            {
                isValid  = false;
                message += "ClientRefId isn't received.";
            }
            else
            {
                if (clientRefId.Value != context.Payment.TrackingNumber.ToString())
                {
                    isValid  = false;
                    message += "ClientRefId isn't valid.";
                }
            }

            if (!isValid)
            {
                message = $"{_options.Messages.InvalidDataReceivedFromGateway}{message}";

                return(PaymentVerifyResult.Failed(message));
            }

            var verificationModel = new VerifyPayRequestModel
            {
                Amount = (long)context.Payment.Amount,
                RefId  = refId.Value
            };

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

            //Send Verify pay Request
            var response = await _httpClient.PostJsonAsync(_pingGatewayOptions.ApiVerificationUrl, verificationModel, cancellationToken);

            //Check if we ran into an Issue
            if (!response.IsSuccessStatusCode)
            {
                return(PaymentVerifyResult.Failed(_options.Messages.PaymentFailed));
            }

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

            var responseModel = JsonConvert.DeserializeObject <VerifyPayResponseModel>(responseBody);

            if (responseModel.Amount != (long)context.Payment.Amount)
            {
                message = $"{_options.Messages.PaymentFailed} Amount is not valid.";

                return(PaymentVerifyResult.Failed(message));
            }

            return(PaymentVerifyResult.Succeed(refId.Value, _options.Messages.PaymentSucceed));
        }