Пример #1
0
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            if (capturePaymentRequest == null)
            {
                throw new ArgumentNullException(nameof(capturePaymentRequest));
            }

            var currentStore = EngineContext.Current.Resolve <IStoreContext>().CurrentStore;

            stripe.Charge charge = capturePaymentRequest.CreateCapture(this._stripePaymentSettings, currentStore);

            if (charge.GetStatus() == StripeChargeStatus.Succeeded)
            {
                //successfully captured
                return(new CapturePaymentResult
                {
                    NewPaymentStatus = PaymentStatus.Paid,
                    CaptureTransactionId = charge.Id
                });
            }
            else
            {
                //successfully captured
                return(new CapturePaymentResult
                {
                    Errors = new List <string>(new [] { $"An error occured attempting to capture charge {charge.Id}." }),
                    NewPaymentStatus = PaymentStatus.Authorized,
                    CaptureTransactionId = charge.Id
                });
            }
        }
Пример #2
0
        public static PaymentStatus GetPaymentStatus(this stripe.Charge charge, TransactionMode transactionMode)
        {
            switch (charge.GetStatus())
            {
            case StripeChargeStatus.Pending:
                return(PaymentStatus.Pending);

            case StripeChargeStatus.Succeeded:
                return(transactionMode == TransactionMode.Authorize ? PaymentStatus.Authorized : PaymentStatus.Paid);

            case StripeChargeStatus.Failed:
            default:
                throw new ArgumentOutOfRangeException("StripeStatus provided unknown.");
            }
        }