Esempio n. 1
0
        protected override PaymentProviderEndPaymentResponse endPayment(IDictionary <string, string> request, string code, string status)
        {
            var result  = new PaymentProviderEndPaymentResponse <ZarinPalBankTranStatus>(Now);
            var _status = SafeClrConvert.ToInt32(status);

            result.ProviderType = this.ProviderType;
            result.StrongStatus = _status.ToEnum <ZarinPalBankTranStatus>();

            string authority = code;

            if (!EndPaymentSucceeded(status))
            {
                result.Status = status;
            }
            else
            {
                var  service = new com.zarinpal.www.PaymentGatewayImplementationService();
                long refId   = 0;
                var  amount  = SafeClrConvert.ToInt32(request["Amount"]);
                _status = service.PaymentVerification(Config.Credentials.MerchantId, authority, amount, out refId);

                result.Query        = authority;
                result.Code         = refId;
                result.StrongStatus = _status.ToEnum <ZarinPalBankTranStatus>();
                result.Status       = _status.ToString();
                result.Succeeded    = _status == 100;
            }

            return(result);
        }
        protected override PaymentProviderEndPaymentResponse endPayment(IDictionary <string, string> request, string code, string status)
        {
            var result = new PaymentProviderEndPaymentResponse <AyandehBankTranStatus>(Now);

            result.ProviderType = this.ProviderType;

            string authority = code;
            long   auth;

            if (!long.TryParse(authority, out auth))
            {
                result.Status = (int)AyandehBankTranStatus.InvalidBankStep2Code;
            }
            else if (!EndPaymentSucceeded(status))
            {
                result.Status = status;
            }
            else
            {
                var  pec       = new ir.shaparak.pec.EShopService();
                byte pecStatus = 0;
                long invoice   = 0;

                pec.PaymentEnquiry(Config.Credentials.Pin, auth, ref pecStatus, ref invoice);

                result.Query     = auth;
                result.Code      = invoice;
                result.Status    = pecStatus;
                result.Succeeded = (EndPaymentSucceeded(pecStatus) && auth != -1);
            }

            return(result);
        }
        protected override PaymentProviderEndPaymentResponse endPayment(IDictionary <string, string> request, string code, string status)
        {
            var result = new PaymentProviderEndPaymentResponse <SamanBankTranStatus>(Now);
            var refnum = code;

            result.ProviderType = this.ProviderType;

            if (string.IsNullOrEmpty(refnum) || !EndPaymentSucceeded(status))
            {
                result.Status = status;
                SamanBankTranStatus strongStatus;
                if (Enum.TryParse <SamanBankTranStatus>(status.Replace(" ", ""), out strongStatus))
                {
                    result.StrongStatus = strongStatus;
                }
            }
            else
            {
                ServicePointManager.ServerCertificateValidationCallback =
                    delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };

                var eservice = new ir.shaparak.sep.PaymentIFBinding();
                var config   = Config as SamanBankConfig;
                var r        = 0.0;

                for (var i = 0; i < config.MaxFinishPaymentRetry; i++)
                {
                    r = eservice.verifyTransaction(refnum, Config.Credentials.Pin);
                    var ri = SafeClrConvert.ToInt32(r);

                    if (ri != 0)
                    {
                        result.Succeeded = EndPaymentSucceeded(ri);
                        break;
                    }
                }

                result.Query  = code;
                result.Code   = "";
                result.Status = r;
            }

            return(result);
        }
        protected override Task <PaymentProviderEndPaymentResponse> endPaymentAsync(IDictionary <string, string> request, string code, string status, CancellationToken cancellation)
        {
            var tcs = new TaskCompletionSource <PaymentProviderEndPaymentResponse>();

            try
            {
                var pec = new ir.shaparak.pec.EShopService();

                pec.PaymentEnquiryCompleted += new PaymentEnquiryCompletedEventHandler((sender, args) =>
                {
                    if (args.Error != null)
                    {
                        tcs.TrySetException(args.Error);
                    }
                    else
                    if (!args.Cancelled)
                    {
                        try
                        {
                            var result = new PaymentProviderEndPaymentResponse <AyandehBankTranStatus>(Now);

                            result.Query        = (long)args.UserState;
                            result.Code         = args.invoiceNumber;
                            result.Status       = args.status;
                            result.Succeeded    = (EndPaymentSucceeded(args.status) && result.Query != -1);
                            result.ProviderType = this.ProviderType;

                            tcs.SetResult(result);
                        }
                        catch (Exception ex)
                        {
                            tcs.TrySetException(ex);
                        }
                    }
                    else
                    {
                        tcs.SetCanceled();
                    }

                    pec.Dispose();
                });

                string authority = code;
                long   auth;
                byte   pecStatus = 0;
                long   invoice   = 0;

                if (!long.TryParse(authority, out auth))
                {
                    var result = new PaymentProviderEndPaymentResponse <AyandehBankTranStatus>();

                    result.Query        = auth;
                    result.Status       = (int)AyandehBankTranStatus.InvalidBankStep2Code;
                    result.Succeeded    = false;
                    result.ProviderType = ProviderType;

                    tcs.SetResult(result);
                }
                else if (!EndPaymentSucceeded(status))
                {
                    var result = new PaymentProviderEndPaymentResponse <AyandehBankTranStatus>();

                    result.Query        = auth;
                    result.Status       = status;
                    result.Succeeded    = false;
                    result.ProviderType = ProviderType;

                    tcs.SetResult(result);
                }
                else
                {
                    cancellation.Register(() => pec.CancelAsync(auth));

                    pec.PaymentEnquiryAsync(Config.Credentials.Pin, auth, pecStatus, invoice, auth);
                }
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }

            return(tcs.Task);
        }
Esempio n. 5
0
        private async Task <PaymentManagerEndPaymentResponse> SaveEndPaymentAsync(string paymentCode, string beginStepCode, IDictionary <string, string> request, PaymentProviderEndPaymentResponse providerResponse, CancellationToken cancellation)
        {
            var result = new PaymentManagerEndPaymentResponse();

            result.QueryCode = beginStepCode;
            result.Request   = request;

            var dbOk = false;

            Logger.LogCategory("SaveEndPaymentAsync");

            if (providerResponse.Succeeded || !Config.SaveOnlySuccessfulOperations)
            {
                Logger.Log("Start saving in the database");

                var args = new
                {
                    Result        = CommandParameter.Output(SqlDbType.VarChar, 50),
                    PaymentCode   = paymentCode,
                    BankType      = providerResponse.ProviderType,
                    BeginStepCode = beginStepCode,
                    StepCode      = SafeClrConvert.ToString(providerResponse.Code),
                    StepStatus    = SafeClrConvert.ToString(providerResponse.Status),
                    StepDate      = providerResponse.Date,
                    StepSucceeded = providerResponse.Succeeded,
                    @StepData     = ""
                };
                var cmd = _db.GetCommand("usp1_Payment_save_end_step");

                result.DbResult = await _db.ExecuteNonQueryAsync(cmd, args, cancellation);

                if (result.DbResult.Success)
                {
                    result.Status = args.Result.Value.ToString();

                    Logger.Log("DbStatus = " + result.Status);

                    dbOk = result.Status == "Success";

                    if (!dbOk)
                    {
                        result.Status = "SaveError";
                    }
                }
                else
                {
                    Logger.Log("Failed: " + result.DbResult.Exception.ToString(","));

                    result.Failed(result.DbResult.Exception);
                }
            }
            else
            {
                dbOk = true;
            }

            if (providerResponse.Succeeded && dbOk)
            {
                result.Succeeded();
            }

            return(result);
        }
        protected override Task <PaymentProviderEndPaymentResponse> endPaymentAsync(IDictionary <string, string> request, string code, string status, CancellationToken cancellation)
        {
            var tcs    = new TaskCompletionSource <PaymentProviderEndPaymentResponse>();
            var refnum = code;

            try
            {
                ServicePointManager.ServerCertificateValidationCallback =
                    delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };
                var eservice = new ir.shaparak.sep.PaymentIFBinding();

                eservice.verifyTransactionCompleted += new verifyTransactionCompletedEventHandler((sender, args) =>
                {
                    if (args.Error != null)
                    {
                        tcs.TrySetException(args.Error);
                    }
                    else
                    if (!args.Cancelled)
                    {
                        try
                        {
                            var result = new PaymentProviderEndPaymentResponse <SamanBankTranStatus>(Now);
                            var config = Config as SamanBankConfig;
                            var r      = 0.0;

                            for (var i = 0; i < config.MaxFinishPaymentRetry; i++)
                            {
                                r      = eservice.verifyTransaction(refnum, Config.Credentials.Pin);
                                var ri = SafeClrConvert.ToInt32(r);

                                if (ri != 0)
                                {
                                    result.Succeeded = EndPaymentSucceeded(ri);
                                    break;
                                }
                            }

                            result.Query        = code;
                            result.Code         = "";
                            result.Status       = r;
                            result.ProviderType = this.ProviderType;

                            tcs.SetResult(result);
                        }
                        catch (Exception ex)
                        {
                            tcs.TrySetException(ex);
                        }
                    }
                    else
                    {
                        tcs.SetCanceled();
                    }

                    eservice.Dispose();
                });

                if (string.IsNullOrEmpty(refnum) || !EndPaymentSucceeded(status))
                {
                    var result = new PaymentProviderEndPaymentResponse <SamanBankTranStatus>();
                    result.ProviderType = this.ProviderType;
                    result.Status       = status;

                    SamanBankTranStatus strongStatus;

                    if (Enum.TryParse <SamanBankTranStatus>(status.Replace(" ", ""), out strongStatus))
                    {
                        result.StrongStatus = strongStatus;
                    }

                    tcs.SetResult(result);
                }
                else
                {
                    cancellation.Register(() => eservice.CancelAsync(refnum));

                    eservice.verifyTransactionAsync(refnum, Config.Credentials.Pin, refnum);
                }
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }

            return(tcs.Task);
        }
Esempio n. 7
0
        protected override Task <PaymentProviderEndPaymentResponse> endPaymentAsync(IDictionary <string, string> request, string code, string status, CancellationToken cancellation)
        {
            var tcs = new TaskCompletionSource <PaymentProviderEndPaymentResponse>();

            try
            {
                var service = new com.zarinpal.www.PaymentGatewayImplementationService();

                service.PaymentVerificationCompleted += new PaymentVerificationCompletedEventHandler((object sender, PaymentVerificationCompletedEventArgs args) =>
                {
                    if (args.Error != null)
                    {
                        tcs.TrySetException(args.Error);
                    }
                    else
                    if (!args.Cancelled)
                    {
                        try
                        {
                            var result = new PaymentProviderEndPaymentResponse <ZarinPalBankTranStatus>(Now);

                            result.Query        = code;
                            result.Code         = args.RefID;
                            result.Status       = args.Result;
                            result.Succeeded    = result.Status.ToString() == "100";
                            result.StrongStatus = args.Result.ToEnum <ZarinPalBankTranStatus>();
                            result.ProviderType = this.ProviderType;

                            tcs.SetResult(result);
                        }
                        catch (Exception ex)
                        {
                            tcs.TrySetException(ex);
                        }
                    }
                    else
                    {
                        tcs.SetCanceled();
                    }

                    service.Dispose();
                });

                var authority = code;
                var amount    = SafeClrConvert.ToInt32(request["Amount"]);

                if (!EndPaymentSucceeded(status))
                {
                    var result = new PaymentProviderEndPaymentResponse <ZarinPalBankTranStatus>();

                    result.Query        = authority;
                    result.Status       = status;
                    result.Succeeded    = false;
                    result.ProviderType = this.ProviderType;

                    tcs.SetResult(result);
                }
                else
                {
                    cancellation.Register(() => service.CancelAsync(authority));

                    service.PaymentVerificationAsync(Config.Credentials.MerchantId, authority, amount, authority);
                }
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }

            return(tcs.Task);
        }