Exemplo n.º 1
0
        private bool doRefund(StripeSession session, Transaction charge, decimal?amount = null, string description = null, object extraData = null)
        {
            var fromActualData = session.FetchAccountData(charge.From);

            var refundAmount = amount ?? charge.Amount.Value;

            try
            {
                var bodyPrms = new Dictionary <string, string>()
                {
                    { PRM_AMOUNT, ((int)((refundAmount * 100))).ToString() }
                };

                if (description.IsNotNullOrWhiteSpace())
                {
                    bodyPrms.Add(PRM_REASON, description);
                }

                var prms = new WebClient.RequestParams(this)
                {
                    UserName       = session.SecretKey,
                    Method         = HTTPRequestMethod.POST,
                    BodyParameters = bodyPrms
                };

                dynamic obj = WebClient.GetJsonAsDynamic(new Uri(REFUND_URI.Args(charge.Token)), prms);

                dynamic lastRefund = ((NFX.Serialization.JSON.JSONDataArray)obj.refunds.Data).First();

                var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

                StatRefund(charge, amount);

                return(true);
            }
            catch (Exception ex)
            {
                StatRefundError();

                var wex = ex as System.Net.WebException;
                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".Refund(money: {0}, card: {1}, description: '{2}')"
                                              .Args(charge.Amount, fromActualData.AccountID, description);
                        PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        if (stripeEx != null)
                        {
                            throw stripeEx;
                        }
                    }
                }

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CAPTURE_CAPTURED_PAYMENT_ERROR + this.GetType()
                                                 + " .Refund(session='{0}', charge='{1}')".Args(session, charge), ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Overload of Charge method with Stripe-typed session parameter
        /// </summary>
        public Transaction Charge(StripeSession session, ITransactionContext context, Account from, Account to, Amount amount, bool capture = true, string description = null, object extraData = null)
        {
            var fromActualData = PaySystemHost.AccountToActualData(context, from);

            try
            {
                var bodyPrms = new Dictionary <string, string>()
                {
                    { PRM_AMOUNT, ((int)((amount.Value * 100))).ToString() },
                    { PRM_CURRENCY, amount.CurrencyISO.ToString().ToLower() },
                    { PRM_DESCRIPTION, description },
                    { PRM_CAPTURE, capture.ToString() }
                };

                fillBodyParametersFromAccount(bodyPrms, fromActualData);

                var prms = new WebClient.RequestParams()
                {
                    Uri            = new Uri(CHARGE_URI),
                    Caller         = this,
                    UName          = session.SecretKey,
                    Method         = HTTPRequestMethod.POST,
                    BodyParameters = bodyPrms
                };

                dynamic obj = WebClient.GetJson(prms);

                var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Charge);

                var ta = new Transaction(taId, TransactionType.Charge, from, to, this.Name, obj.id, amount, created, description);

                StatCharge(amount);

                return(ta);
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;

                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".Charge(money: {0}, card: {1}, amount: '{2}')".Args(amount.Value, fromActualData.AccountNumber, amount);
                        var stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        throw stripeEx;
                    }
                }

                StatChargeError();

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CHARGE_PAYMENT_ERROR + this.GetType()
                                                 + " .Capture(session='{0}', card='{1}', amount='{2}')".Args(session, from, amount), ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Transfers funds to customerAccount from current stripe account
        /// (which credentials is supplied in current session)
        /// </summary>
        private Transaction transfer(StripeSession stripeSession, ITransactionContext context, string recipientID, Account customerAccount, Amount amount, string description)
        {
            var actualAccountData = PaySystemHost.AccountToActualData(context, customerAccount);

            try
            {
                var prms = new WebClient.RequestParams()
                {
                    Uri            = new Uri(TRANSFER_URI),
                    Caller         = this,
                    UName          = stripeSession.SecretKey,
                    Method         = HTTPRequestMethod.POST,
                    BodyParameters = new Dictionary <string, string>()
                    {
                        { PRM_RECIPIENT, recipientID },
                        { PRM_AMOUNT, ((int)((amount.Value * 100))).ToString() },
                        { PRM_CURRENCY, amount.CurrencyISO.ToLower() },
                        { PRM_DESCRIPTION, description }
                    }
                };

                dynamic obj = WebClient.GetJson(prms);

                var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

                var taId = PaySystemHost.GenerateTransactionID(stripeSession, context, TransactionType.Transfer);

                var ta = new Transaction(taId, TransactionType.Transfer, Account.EmptyInstance, customerAccount, this.Name, obj.id, amount, created, description);

                StatTransfer(amount);

                return(ta);
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;
                if (wex == null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".transfer(recipientID='{0}', customerAccount='{1}', amount='{2}')".Args(recipientID, actualAccountData, amount);
                        PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        if (stripeEx != null)
                        {
                            throw stripeEx;
                        }
                    }
                }

                StatTransferError();

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_TRANSFER_ERROR + this.GetType()
                                                 + " .transfer(customerAccout='{0}')".Args(actualAccountData), ex);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates new recipient in Stripe system.
        /// Is used as a temporary entity to substitute recipient parameter in Transfer operation then deleted
        /// </summary>
        private string createRecipient(StripeSession stripeSession, ITransactionContext context, Account recipientAccount, string description)
        {
            var recipientActualAccountData = PaySystemHost.AccountToActualData(context, recipientAccount);

            try
            {
                var bodyPrms = new Dictionary <string, string>()
                {
                    { PRM_NAME, recipientActualAccountData.AccountTitle },
                    { PRM_TYPE, recipientActualAccountData.AccountType == AccountType.Corporation ? "corporation" : "individual" },
                    { PRM_EMAIL, recipientActualAccountData.BillingEmail }
                };

                fillBodyParametersFromAccount(bodyPrms, recipientActualAccountData);

                var prms = new WebClient.RequestParams()
                {
                    Uri            = new Uri(RECIPIENT_URI),
                    Caller         = this,
                    UName          = stripeSession.SecretKey,
                    Method         = HTTPRequestMethod.POST,
                    BodyParameters = bodyPrms
                };

                dynamic obj = WebClient.GetJson(prms);

                return(obj.id);
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;
                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".createRecipient(customerAccout='{0}')".Args(recipientActualAccountData);
                        PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        if (stripeEx != null)
                        {
                            throw stripeEx;
                        }
                    }
                }

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CREATE_RECIPIENT_ERROR + this.GetType()
                                                 + " .Refund(customerAccout='{0}')".Args(recipientActualAccountData), ex);
            }

            throw new NotImplementedException();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Overload of Capture method with Stripe-typed session parameter
        /// </summary>
        public Transaction Capture(StripeSession session, ITransactionContext context, ref Transaction charge, Amount?amount = null, string description = null, object extraData = null)
        {
            try
            {
                var bodyPrms = new Dictionary <string, string>();

                if (amount.HasValue)
                {
                    bodyPrms.Add(PRM_AMOUNT, ((int)((amount.Value.Value * 100))).ToString());
                }

                var prms = new WebClient.RequestParams()
                {
                    Uri            = new Uri(CAPTURE_URI.Args(charge.ProcessorToken)),
                    Caller         = this,
                    Method         = HTTPRequestMethod.POST,
                    UName          = session.SecretKey,
                    BodyParameters = bodyPrms
                };

                dynamic obj = WebClient.GetJsonAsDynamic(prms);

                StatCapture(charge, amount);
                return(charge);
            }
            catch (Exception ex)
            {
                StatCaptureError();

                var wex = ex as System.Net.WebException;
                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name + ".Capture(id: {0})".Args(charge.ID);
                        var    stripeEx     = PaymentStripeException.Compose(response, errorMessage, wex);
                        throw stripeEx;
                    }
                }

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CAPTURE_CAPTURED_PAYMENT_ERROR + this.GetType()
                                                 + " .Capture(session='{0}', charge='{1}')".Args(session, charge), ex);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Deletes existing recipient in Stripe system.
        /// It is used to delete temporary recipient created to perform Transfer operation
        /// </summary>
        private void deleteRecipient(StripeSession stripeSession, string recipientID)
        {
            try
            {
                var prms = new WebClient.RequestParams()
                {
                    Uri    = new Uri(RECIPIENT_DELETE_URI.Args(recipientID)),
                    Caller = this,
                    UName  = stripeSession.SecretKey,
                    Method = HTTPRequestMethod.DELETE
                };

                dynamic obj = WebClient.GetJson(prms);

                return;
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;
                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".deleteRecipient(recipientID: '{0}')".Args(recipientID);
                        PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        if (stripeEx != null)
                        {
                            throw stripeEx;
                        }
                    }
                }

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CREATE_RECIPIENT_ERROR + this.GetType()
                                                 + " .deleteRecipient(recipientID: '{0}')".Args(recipientID), ex);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Overload of Refund method with Stripe-typed session parameter
        /// Developers, don't call this method directly. Call Transaction.Refund instead.
        /// </summary>
        public Transaction Refund(StripeSession session, ITransactionContext context, ref Transaction charge, Amount?amount = null, string description = null, object extraData = null)
        {
            var fromActualData = PaySystemHost.AccountToActualData(context, charge.From);

            var refundAmount = amount ?? charge.Amount;

            try
            {
                var bodyPrms = new Dictionary <string, string>()
                {
                    { PRM_AMOUNT, ((int)((refundAmount.Value * 100))).ToString() }
                };

                if (description.IsNotNullOrWhiteSpace())
                {
                    bodyPrms.Add(PRM_REASON, description);
                }

                var prms = new WebClient.RequestParams()
                {
                    Uri            = new Uri(REFUND_URI.Args(charge.ProcessorToken)),
                    Caller         = this,
                    UName          = session.SecretKey,
                    Method         = HTTPRequestMethod.POST,
                    BodyParameters = bodyPrms
                };

                dynamic obj = WebClient.GetJson(prms);

                dynamic lastRefund = ((NFX.Serialization.JSON.JSONDataArray)obj.refunds.Data).First();

                var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

                var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Refund);

                var refundTA = new Transaction(taId, TransactionType.Refund, Account.EmptyInstance, charge.From, this.Name,
                                               lastRefund["id"], refundAmount, created, description,
                                               isCaptured: true, canRefund: false);

                StatRefund(charge, amount);

                return(refundTA);
            }
            catch (Exception ex)
            {
                var wex = ex as System.Net.WebException;
                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".Refund(money: {0}, card: {1}, description: '{2}')"
                                              .Args(charge.Amount, fromActualData.AccountNumber, description);
                        PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        if (stripeEx != null)
                        {
                            throw stripeEx;
                        }
                    }
                }

                StatRefundError();

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CAPTURE_CAPTURED_PAYMENT_ERROR + this.GetType()
                                                 + " .Refund(session='{0}', charge='{1}')".Args(session, charge), ex);
            }
        }
Exemplo n.º 8
0
      /// <summary>
      /// Deletes existing recipient in Stripe system.
      /// It is used to delete temporary recipient created to perform Transfer operation
      /// </summary>
      private void deleteRecipient(StripeSession stripeSession, string recipientID)
      {
        try
        {
          var prms = new WebClient.RequestParams()
          {
            Uri = new Uri(RECIPIENT_DELETE_URI.Args(recipientID)),
            Caller = this,
            UName = stripeSession.SecretKey,
            Method = HTTPRequestMethod.DELETE
          };

          dynamic obj = WebClient.GetJson(prms);

          return;
        }
        catch (Exception ex)
        {
          var wex = ex as System.Net.WebException;
          if (wex != null)
          {
            var response = wex.Response as System.Net.HttpWebResponse;
            if (response != null)
            {
              string errorMessage = this.GetType().Name +
                        ".deleteRecipient(recipientID: '{0}')".Args(recipientID);
              PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
              if (stripeEx != null) throw stripeEx; 
            }
          }

          throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CREATE_RECIPIENT_ERROR + this.GetType()
            + " .deleteRecipient(recipientID: '{0}')".Args(recipientID), ex);
        }
      }
Exemplo n.º 9
0
      /// <summary>
      /// Creates new recipient in Stripe system.
      /// Is used as a temporary entity to substitute recipient parameter in Transfer operation then deleted
      /// </summary>
      private string createRecipient(StripeSession stripeSession, ITransactionContext context, Account recipientAccount, string description)
      {
        var recipientActualAccountData = PaySystemHost.AccountToActualData(context, recipientAccount);

        try
        {
          var bodyPrms = new Dictionary<string, string>() 
          {
            {PRM_NAME, recipientActualAccountData.AccountTitle},
            {PRM_TYPE, recipientActualAccountData.AccountType == AccountType.Corporation ? "corporation" : "individual"},
            {PRM_EMAIL, recipientActualAccountData.BillingEmail}
          };

          fillBodyParametersFromAccount(bodyPrms, recipientActualAccountData);

          var prms = new WebClient.RequestParams()
          {
            Uri = new Uri(RECIPIENT_URI),
            Caller = this,
            UName = stripeSession.SecretKey,
            Method = HTTPRequestMethod.POST,
            BodyParameters = bodyPrms
          };

          dynamic obj = WebClient.GetJson(prms);

          return obj.id;
        }
        catch (Exception ex)
        {
          var wex = ex as System.Net.WebException;
          if (wex != null)
          {
            var response = wex.Response as System.Net.HttpWebResponse;
            if (response != null)
            {
              string errorMessage = this.GetType().Name +
                ".createRecipient(customerAccout='{0}')".Args(recipientActualAccountData);
              PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
              if (stripeEx != null) throw stripeEx;
            }
          }

          throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CREATE_RECIPIENT_ERROR + this.GetType()
            + " .Refund(customerAccout='{0}')".Args(recipientActualAccountData), ex);
        }

        throw new NotImplementedException();
      }
Exemplo n.º 10
0
      /// <summary>
      /// Transfers funds to customerAccount from current stripe account 
      /// (which credentials is supplied in current session)
      /// </summary>
      private Transaction transfer(StripeSession stripeSession, ITransactionContext context, string recipientID, Account customerAccount, Amount amount, string description)
      {
        var actualAccountData = PaySystemHost.AccountToActualData(context, customerAccount);

        try
        {
          var prms = new WebClient.RequestParams()
          {
            Uri = new Uri(TRANSFER_URI),
            Caller = this,
            UName = stripeSession.SecretKey,
            Method = HTTPRequestMethod.POST,
            BodyParameters = new Dictionary<string, string>() 
            {
              {PRM_RECIPIENT, recipientID},
              {PRM_AMOUNT, ((int)((amount.Value * 100))).ToString()},
              {PRM_CURRENCY, amount.CurrencyISO.ToLower()},
              {PRM_DESCRIPTION, description}
            }
          };

          dynamic obj = WebClient.GetJson(prms);

          var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

          var taId = PaySystemHost.GenerateTransactionID(stripeSession, context, TransactionType.Transfer);

          var ta = new Transaction(taId, TransactionType.Transfer, this.Name, obj.id, Account.EmptyInstance, customerAccount, amount, created, description);

          StatTransfer(amount);

          return ta;
        }
        catch (Exception ex)
        {
          StatTransferError();

          var wex = ex as System.Net.WebException;
          if (wex == null)
          {
            var response = wex.Response as System.Net.HttpWebResponse;
            if (response != null)
            {
              string errorMessage = this.GetType().Name +
                        ".transfer(recipientID='{0}', customerAccount='{1}', amount='{2}')".Args(recipientID, actualAccountData, amount);
              PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
              if (stripeEx != null) throw stripeEx; 
            }
          }

          throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_TRANSFER_ERROR + this.GetType()
            + " .transfer(customerAccout='{0}')".Args(actualAccountData), ex);
        }
      }
Exemplo n.º 11
0
      /// <summary>
      /// Overload of Refund method with Stripe-typed session parameter
      /// Developers, don't call this method directly. Call Transaction.Refund instead.
      /// </summary>
      public Transaction Refund(StripeSession session, ITransactionContext context, ref Transaction charge, Amount? amount = null, string description = null, object extraData = null)
      {
        var fromActualData = PaySystemHost.AccountToActualData(context, charge.From);

        var refundAmount = amount ?? charge.Amount;

        try
        {
          var bodyPrms = new Dictionary<string, string>() { 
            {PRM_AMOUNT, ((int)((refundAmount.Value * 100))).ToString()}
          };

          if (description.IsNotNullOrWhiteSpace())
            bodyPrms.Add(PRM_REASON, description);

          var prms = new WebClient.RequestParams()
          {
            Uri = new Uri(REFUND_URI.Args(charge.ProcessorToken)),
            Caller = this,
            UName = session.SecretKey,
            Method = HTTPRequestMethod.POST,
            BodyParameters = bodyPrms
          };

          dynamic obj = WebClient.GetJson(prms);

          dynamic lastRefund = ((NFX.Serialization.JSON.JSONDataArray)obj.refunds.data.Data).First();

          var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

          var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Refund);

          var refundTA = new Transaction(taId, TransactionType.Refund, this.Name,
            lastRefund["id"], Account.EmptyInstance, charge.From, refundAmount, created, description, canRefund: false);

          StatRefund(charge, amount);

          return refundTA;
        }
        catch (Exception ex)
        {
          StatRefundError();

          var wex = ex as System.Net.WebException;
          if (wex != null)
          {
            var response = wex.Response as System.Net.HttpWebResponse;
            if (response != null)
            {
              string errorMessage = this.GetType().Name +
                ".Refund(money: {0}, card: {1}, description: '{2}')"
                  .Args(charge.Amount, fromActualData.AccountNumber, description);
              PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
              if (stripeEx != null) throw stripeEx;
            }
          }

          throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CAPTURE_CAPTURED_PAYMENT_ERROR + this.GetType()
            + " .Refund(session='{0}', charge='{1}')".Args(session, charge), ex);
        }
      }
Exemplo n.º 12
0
      /// <summary>
      /// Overload of Capture method with Stripe-typed session parameter
      /// </summary>
      public void Capture(StripeSession session, ITransactionContext context, ref Transaction charge, Amount? amount = null, string description = null, object extraData = null)
      {
        try
        {
          var bodyPrms = new Dictionary<string, string>();

          if (amount.HasValue)
          {
            bodyPrms.Add(PRM_AMOUNT, ((int)((amount.Value.Value * 100))).ToString());
          }

          var prms = new WebClient.RequestParams()
          {
            Uri = new Uri(CAPTURE_URI.Args(charge.ProcessorToken)),
            Caller = this,
            Method = HTTPRequestMethod.POST,
            UName = session.SecretKey,
            BodyParameters = bodyPrms
          };

          dynamic obj = WebClient.GetJson(prms);

          StatCapture(charge, amount);
        }
        catch (Exception ex)
        {
          StatCaptureError();

          var wex = ex as System.Net.WebException;
          if (wex != null)
          {
            var response = wex.Response as System.Net.HttpWebResponse;
            if (response != null)
            {
              string errorMessage = this.GetType().Name + ".Capture(id: {0})".Args(charge.ID);
              var stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
              throw stripeEx;
            }
          }

          throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CAPTURE_CAPTURED_PAYMENT_ERROR + this.GetType()
            + " .Capture(session='{0}', charge='{1}')".Args(session, charge), ex);
        }
      }
Exemplo n.º 13
0
      /// <summary>
      /// Overload of Charge method with Stripe-typed session parameter
      /// </summary>
      public Transaction Charge(StripeSession session, ITransactionContext context, Account from, Account to, Amount amount, bool capture = true, string description = null, object extraData = null)
      {
        var fromActualData = PaySystemHost.AccountToActualData(context, from);

        try
        {
          var bodyPrms = new Dictionary<string, string>() { 
            {PRM_AMOUNT, ((int)((amount.Value * 100))).ToString()},
            {PRM_CURRENCY, amount.CurrencyISO.ToString().ToLower()},
            {PRM_DESCRIPTION, description},
            {PRM_CAPTURE, capture.ToString()}
          };

          fillBodyParametersFromAccount(bodyPrms, fromActualData);

          var prms = new WebClient.RequestParams() {
            Uri = new Uri(CHARGE_URI),
            Caller = this,
            UName = session.SecretKey,
            Method = HTTPRequestMethod.POST,
            BodyParameters = bodyPrms
          };

          dynamic obj = WebClient.GetJson(prms);

          var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

          var taId = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Charge);

          var ta = new Transaction(taId, TransactionType.Charge, this.Name, obj.id, from, to, amount, created, description);

          StatCharge(amount);

          return ta;
        }
        catch (Exception ex)
        {
          StatChargeError();

          var wex = ex as System.Net.WebException;

          if (wex != null)
          {
            var response = wex.Response as System.Net.HttpWebResponse;
            if (response != null)
            {
              string errorMessage = this.GetType().Name +
                ".Charge(money: {0}, card: {1}, amount: '{2}')".Args(amount.Value, fromActualData.AccountNumber, amount);
              var stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
              throw stripeEx;  
            }
          }

          throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CHARGE_PAYMENT_ERROR + this.GetType()
            + " .Capture(session='{0}', card='{1}', amount='{2}')".Args(session, from, amount), ex);
        }
      }
Exemplo n.º 14
0
 private bool doVoid(StripeSession session, Transaction charge, string description = null, object extraData = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
        private Transaction doCharge(StripeSession session, Account from, Account to, Amount amount, bool capture = true, string description = null, object extraData = null)
        {
            var fromActualData = session.FetchAccountData(from);

            try
            {
                var bodyPrms = new Dictionary <string, string>()
                {
                    { PRM_AMOUNT, ((int)((amount.Value * 100))).ToString() },
                    { PRM_CURRENCY, amount.CurrencyISO.ToString().ToLower() },
                    { PRM_DESCRIPTION, description },
                    { PRM_CAPTURE, capture.ToString() }
                };

                fillBodyParametersFromAccount(bodyPrms, fromActualData);

                var prms = new WebClient.RequestParams(this)
                {
                    UserName       = session.SecretKey,
                    Method         = HTTPRequestMethod.POST,
                    BodyParameters = bodyPrms
                };

                dynamic obj = WebClient.GetJsonAsDynamic(new Uri(CHARGE_URI), prms);

                var created = ((long)obj.created).FromSecondsSinceUnixEpochStart();

                var taId = session.GenerateTransactionID(TransactionType.Charge);

                var ta = new Transaction(taId, TransactionType.Charge, TransactionStatus.Success, from, to, this.Name, obj.AsGDID, created, amount, description: description, extraData: extraData);

                if (capture)
                {
                    ta.__Apply(Transaction.Operation.Capture(TransactionStatus.Success, created, token: obj.AsGDID, description: description, amount: amount.Value, extraData: extraData));
                }

                StatCharge(amount);

                return(ta);
            }
            catch (Exception ex)
            {
                StatChargeError();

                var wex = ex as System.Net.WebException;

                if (wex != null)
                {
                    var response = wex.Response as System.Net.HttpWebResponse;
                    if (response != null)
                    {
                        string errorMessage = this.GetType().Name +
                                              ".Charge(money: {0}, card: {1}, amount: '{2}')".Args(amount.Value, fromActualData.AccountID, amount);
                        var stripeEx = PaymentStripeException.Compose(response, errorMessage, wex);
                        throw stripeEx;
                    }
                }

                throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CHARGE_PAYMENT_ERROR + this.GetType()
                                                 + " .Capture(session='{0}', card='{1}', amount='{2}')".Args(session, from, amount), ex);
            }
        }