Exemple #1
0
        public override ApiInfo CapturePayment(Order order, IDictionary <string, string> settings)
        {
            try
            {
                order.MustNotBeNull("order");
                settings.MustNotBeNull("settings");
                settings.MustContainKey("mode", "settings");
                settings.MustContainKey(settings["mode"] + "_secret_key", "settings");

                var apiKey = settings[settings["mode"] + "_secret_key"];

                var chargeService = new ChargeService(apiKey);

                var captureOptions = new ChargeCaptureOptions()
                {
                    Amount = DollarsToCents(order.TransactionInformation.AmountAuthorized.Value)
                };

                var charge = chargeService.Capture(order.TransactionInformation.TransactionId, captureOptions);

                return(new ApiInfo(charge.Id, GetPaymentState(charge)));
            }
            catch (Exception exp)
            {
                LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - GetStatus", exp);
            }

            return(null);
        }
 public void TestEvent(Object sender, EventArgs e)
 {
     try
     {
         var chargeOptions = new ChargeCaptureOptions
         {
             Amount = 3000,
         };
         var    chargeService = new ChargeService();
         Charge charge        = chargeService.Capture("ch_1DZFGDBXLNpDm6rJAZgwGBuz", chargeOptions, null);
     }
     catch (Exception ex)
     {
     }
 }
Exemple #3
0
        public static Charge CaptureCharge(string chargeId, decimal amount)
        {
            // Set your secret key: remember to change this to your live secret key in production
            // See your keys here: https://dashboard.stripe.com/account/apikeys
            StripeConfiguration.SetApiKey(SecretKey);

            string PaidAmountString = ConvertDecimalAmountToZeroDecimal(amount);

            var options = new ChargeCaptureOptions
            {
                Amount = Convert.ToInt64(PaidAmountString),
            };
            var    service = new ChargeService();
            Charge charge  = service.Capture(chargeId, options);

            return(charge);
        }
Exemple #4
0
        public void chargePenalty(string chargeId)
        {
            try
            {
                StripeConfiguration.SetApiKey("sk_test_Q5wSnyXL03yN0KpPaAMYttOb");
                var chargeOptions = new ChargeCaptureOptions
                {
                    Amount = 1000,
                };
                var    chargeService = new ChargeService();
                Charge charge        = chargeService.Capture(chargeId, chargeOptions, null);

                DisplayAlert("", "$10 will be charge on your account as penalty", "Ok");
            }catch (Exception ex)
            {
                DisplayAlert("", ExceptionManagement.LogException(ex), "Ok");
            }
        }
Exemple #5
0
        public static Charge MakeCapture(string customerId, string chargeId, string orderId, string clientId)
        {
            StripeConfiguration.ApiKey = "sk_test_dBR2X5yRuQklppKxRz7jCbuT";

            var chargeUpdateOptions = new ChargeUpdateOptions()
            {
                Description = orderId
            };

            var chargeService = new ChargeService();

            chargeService.Update(chargeId, chargeUpdateOptions);


            Charge charge = chargeService.Capture(chargeId, null);

            return(charge);
        }
Exemple #6
0
        public static TransactionResult ProcessCapture(TransactionRequest captureRequest, StripeSettings stripeSettings, ILogger logger)
        {
            InitStripe(stripeSettings, true);
            var chargeService = new ChargeService();
            var chargeId      = captureRequest.GetParameterAs <string>("chargeId");
            var charge        = chargeService.Capture(chargeId, new ChargeCaptureOptions()
            {
                Amount = 100 * (long)(captureRequest.Amount ?? captureRequest.Order.OrderTotal)
            });
            var captureResult = new TransactionResult()
            {
                ResponseParameters = new Dictionary <string, object>()
                {
                    { "chargeId", charge.Id },
                    { "balanceTransactionId", charge.BalanceTransactionId },
                    { "disputeId", charge.DisputeId },
                    { "invoiceId", charge.InvoiceId },
                },
                OrderGuid         = captureRequest.Order.Guid,
                TransactionAmount = (decimal)charge.Amount / 100
            };

            if (charge.Status == "failed")
            {
                logger.Log <TransactionResult>(LogLevel.Warning, "The capture for Order#" + captureRequest.Order.Id + " by stripe failed.");
                captureResult.Success   = false;
                captureResult.Exception = new Exception("An error occurred while processing capture");
                return(captureResult);
            }
            if (charge.Captured.GetValueOrDefault())
            {
                captureResult.NewStatus = PaymentStatus.Complete;
                captureResult.Success   = true;
            }

            return(captureResult);
        }
Exemple #7
0
        public ServiceOperationResult <Charge> CaptureCharge(string chargeId)
        {
            try
            {
                var    service = new ChargeService();
                Charge charge  = service.Capture(chargeId, null);

                ServiceOperationResult <Charge> result = new ServiceOperationResult <Charge>();

                result.IsSuccessfull = true;
                result.Item          = charge;

                return(result);
            }
            catch (StripeException e)
            {
                ServiceOperationResult <Charge> result = new ServiceOperationResult <Charge>();

                result.IsSuccessfull = false;
                result.Errors        = new List <ErrorCodes>();

                switch (e.StripeError.ErrorType)
                {
                case "card_error":

                    switch (e.StripeError.Code)
                    {
                    case "amount_too_small":
                        result.Errors.Add(ErrorCodes.PaymentAmountTooSmall);
                        break;

                    case "amount_too_large":
                        result.Errors.Add(ErrorCodes.PaymentAmountTooLarge);
                        break;

                    case "balance_insufficient":
                        result.Errors.Add(ErrorCodes.PaymentBalanceInsufficient);
                        break;

                    case "expired_card":
                        result.Errors.Add(ErrorCodes.PaymentExpiredCard);
                        break;

                    default:
                        result.Errors.Add(ErrorCodes.PaymentUnknownError);
                        break;
                    }

                    break;

                case "api_connection_error":
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;

                case "api_error":
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;

                case "authentication_error":
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;

                case "invalid_request_error":
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;

                case "rate_limit_error":
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;

                case "validation_error":
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;

                default:
                    result.Errors.Add(ErrorCodes.PaymentUnknownError);
                    break;
                }

                return(result);
            }
        }