public override Task <ShetabPaymentStep1> BeginPaymentAsync(string paymentcode, decimal amount, string returnUrl, System.Threading.CancellationToken cancellation)
        {
            var tcs = new TaskCompletionSource <ShetabPaymentStep1>();

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

                pec.PinPaymentRequestCompleted += new PinPaymentRequestCompletedEventHandler((sender, args) =>
                {
                    if (args.Error != null)
                    {
                        tcs.TrySetException(args.Error);
                    }
                    else
                    if (!args.Cancelled)
                    {
                        try
                        {
                            var result      = new ShetabPaymentStep1 <ParsianBankTranStatus>();
                            result.BankType = this.BankType;
                            result.Code     = args.authority;
                            result.SendData.Add("au", args.authority.ToString());
                            result.Status     = args.status;
                            result.Succeeded  = (args.status == 0 && args.authority != -1);
                            result.GatewayUrl = Config.GatewayUrl + "?au=" + args.authority.ToString();
                            result.SendMethod = Config.GatewayMethod;

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

                    pec.Dispose();
                });

                var  orderid   = SafeClrConvert.ToInt32(paymentcode);
                var  pay       = SafeClrConvert.ToInt32(amount);
                byte pecStatus = 0;
                long auth      = 0;

                cancellation.Register(() => pec.CancelAsync(paymentcode));

                pec.PinPaymentRequestAsync(Config.Credentials.Pin, pay, orderid, returnUrl, auth, pecStatus, paymentcode);
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }

            return(tcs.Task);
        }
        public override ShetabPaymentStep1 BeginPayment(string paymentcode, decimal amount, string returnUrl)
        {
            var result = new ShetabPaymentStep1 <ParsianBankTranStatus>();

            result.BankType = this.BankType;

            var  pec       = new ir.shaparak.pec.EShopService();
            var  orderid   = SafeClrConvert.ToInt32(paymentcode);
            var  pay       = SafeClrConvert.ToInt32(amount);
            byte pecStatus = 0;
            long auth      = 0;

            pec.PinPaymentRequest(Config.Credentials.Pin, pay, orderid, returnUrl, ref auth, ref pecStatus);

            result.Code = auth;
            result.SendData.Add("au", auth.ToString());
            result.Status     = pecStatus;
            result.Succeeded  = (pecStatus == 0 && auth != -1);
            result.GatewayUrl = Config.GatewayUrl + "?au=" + auth.ToString();
            result.SendMethod = Config.GatewayMethod;

            return(result);
        }