Пример #1
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 callbackResult = await PayPingGatewayHelper.GetCallbackResult(
                _httpContextAccessor.HttpContext.Request,
                context,
                _options.Messages,
                cancellationToken);

            if (!callbackResult.IsSucceed)
            {
                return(PaymentVerifyResult.Failed(callbackResult.Message));
            }

            var verificationModel = PayPingGatewayHelper.CreateVerificationModel(context, callbackResult);

            _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)
            {
                var message = $"{_options.Messages.PaymentFailed} Amount is not valid.";

                return(PaymentVerifyResult.Failed(message));
            }

            return(PaymentVerifyResult.Succeed(callbackResult.RefId, _options.Messages.PaymentSucceed));
        }
Пример #2
0
        /// <inheritdoc />
        public override async Task <IPaymentFetchResult> FetchAsync(InvoiceContext context, CancellationToken cancellationToken = default)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var callbackResult = await PayPingGatewayHelper.GetCallbackResult(
                _httpContextAccessor.HttpContext.Request,
                context,
                _options.Messages,
                cancellationToken);

            if (callbackResult.IsSucceed)
            {
                return(PaymentFetchResult.ReadyForVerifying());
            }

            return(PaymentFetchResult.Failed(callbackResult.Message));
        }
Пример #3
0
        private async Task <PayPingCallbackResult> GetCallbackResult(InvoiceContext context, CancellationToken cancellationToken)
        {
            var callBackTransaction = context.Transactions.SingleOrDefault(x => x.Type == TransactionType.Callback);

            PayPingCallbackResult callbackResult;

            if (callBackTransaction == null)
            {
                callbackResult = await PayPingGatewayHelper.GetCallbackResult(
                    _httpContextAccessor.HttpContext.Request,
                    context,
                    _options.Messages,
                    cancellationToken);
            }
            else
            {
                callbackResult =
                    JsonConvert.DeserializeObject <PayPingCallbackResult>(callBackTransaction.AdditionalData);
            }

            return(callbackResult);
        }