示例#1
0
        public virtual async Task <VerifyPaymentResult> VerifyPayment(TblInvoices invoice)
        {
            var result = new VerifyPaymentResult();
            var token  = invoice.PaymentGatewayToken;

            var request = HttpContext.Current.Request;

            if (string.IsNullOrWhiteSpace(request.QueryString["Status"]) ||
                string.IsNullOrWhiteSpace(request.QueryString["token"]))
            {
                result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.PayPal.StatusOrTokenInvalid");
                return(result);
            }
            if (!request.QueryString["Status"].Equals("OK"))
            {
                result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.PayPal.StatusFieldIsNotOK");
                return(result);
            }

            await Task.Run(() =>
            {
                try
                {
                    var service      = new PayPalAPIInterfaceServiceService(GetPayPalConfig());
                    var getEcWrapper = new GetExpressCheckoutDetailsReq
                    {
                        GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
                    };
                    var getEcResponse  = service.GetExpressCheckoutDetails(getEcWrapper);
                    var ecRequest      = new DoExpressCheckoutPaymentRequestType();
                    var requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
                    ecRequest.DoExpressCheckoutPaymentRequestDetails = requestDetails;
                    requestDetails.PaymentDetails = getEcResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
                    requestDetails.Token          = token;
                    requestDetails.PayerID        = getEcResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                    requestDetails.PaymentAction  = PaymentActionCodeType.SALE;
                    var wrapper = new DoExpressCheckoutPaymentReq {
                        DoExpressCheckoutPaymentRequest = ecRequest
                    };
                    var doEcResponse = service.DoExpressCheckoutPayment(wrapper);

                    if (doEcResponse.Ack == AckCodeType.SUCCESS)
                    {
                        result.IsSuccess     = true;
                        result.TransactionId = doEcResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;
                    }
                    else
                    {
                        foreach (var error in doEcResponse.Errors)
                        {
                            result.ErrorMessage +=
                                $"[{error.SeverityCode}] {error.ErrorCode} : {error.LongMessage} </br>";
                        }
                    }
                }
                catch
                {
                    result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.PayPal.ServiceUnavailable");
                }
            });

            return(result);
        }
示例#2
0
        public virtual async Task <VerifyPaymentResult> VerifyPayment(TblInvoices invoice)
        {
            var settings = await _settingService.LoadSettingAsync <ZarinPalSettingsModel>();

            var currentCurrency = DependencyResolver.Current.GetService <IWorkContext>().CurrentCurrency;
            var amount          = invoice.ComputeInvoiceTotalAmount();

            if (string.Compare(currentCurrency.IsoCode, "irr", StringComparison.OrdinalIgnoreCase) == 0)
            {
                amount = amount / 10;
            }

            var result = new VerifyPaymentResult();
            var token  = invoice.PaymentGatewayToken;

            var request = HttpContext.Current.Request;

            if (string.IsNullOrWhiteSpace(request.QueryString["Status"]) ||
                string.IsNullOrWhiteSpace(request.QueryString["Authority"]))
            {
                result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.Zarinpal.StatusOrAuthorityInvalid");
                return(result);
            }
            if (!request.QueryString["Status"].Equals("OK"))
            {
                result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.Zarinpal.StatusFieldIsNotOK");
                return(result);
            }

            var  zResult         = 0;
            long refId           = 0;
            var  connectionError = false;
            await Task.Run(() =>
            {
                try
                {
                    using (var zarinpal = new com.zarinpal.www.PaymentGatewayImplementationService()
                    {
                        Url = settings.ZarinpalWebserviceUrl
                    })
                    {
                        zResult = zarinpal.PaymentVerification(settings.MerchantId,
                                                               token,
                                                               (int)amount,
                                                               out refId);
                    }
                }
                catch
                {
                    connectionError = true;
                }
            });

            if (zResult == 100)
            {
                result.IsSuccess     = true;
                result.TransactionId = refId.ToString();
            }
            else
            {
                result.ErrorMessage = connectionError ?
                                      _localizationService.GetResource("Plugin.PaymentMethod.Zarinpal.ServiceUnavailable") :
                                      $"[{zResult}] : {GetErrorDes(zResult)}";
            }

            return(result);
        }