public IPaymentResult PriorAuthorizeCapturePayment(IInvoice invoice, IPayment payment) { string stripeChargeId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.StripeChargeId); string url = string.Format("https://api.stripe.com/v1/charges/{0}/capture", stripeChargeId); try { var response = StripeHelper.MakeStripeApiRequest(url, "POST", null, _settings); return(GetCapturePaymentResult(invoice, payment, response)); } catch (WebException ex) { return(GetCapturePaymentResult(invoice, payment, (HttpWebResponse)ex.Response)); } }
/// <summary> /// Processes the Authorize and AuthorizeAndCapture transactions /// </summary> /// <param name="invoice">The <see cref="IInvoice" /> to be paid</param> /// <param name="payment">The <see cref="IPayment" /> record</param> /// <param name="transactionMode">Authorize or AuthorizeAndCapture</param> /// <param name="amount">The money amount to be processed</param> /// <param name="creditCard">The <see cref="CreditCardFormData" /></param> /// <returns>The <see cref="IPaymentResult" /></returns> public IPaymentResult ProcessPayment(IInvoice invoice, IPayment payment, TransactionMode transactionMode, decimal amount, CreditCardFormData creditCard) { if (!IsValidCurrencyCode(invoice.CurrencyCode())) { return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception("Invalid currency")), invoice, false)); } // The minimum amount is $0.50 (or equivalent in charge currency). // Test that the payment meets the minimum amount (for USD only). if (invoice.CurrencyCode() == "USD") { if (amount < 0.5m) { return (new PaymentResult( Attempt <IPayment> .Fail(payment, new Exception("Invalid amount (less than 0.50 USD)")), invoice, false)); } } else { if (amount < 1) { return (new PaymentResult( Attempt <IPayment> .Fail(payment, new Exception("Invalid amount (less than 1 " + invoice.CurrencyCode() + ")")), invoice, false)); } } var requestParams = StripeHelper.PreparePostDataForProcessPayment(invoice.GetBillingAddress(), transactionMode, ConvertAmount(invoice, amount), invoice.CurrencyCode(), creditCard, invoice.PrefixedInvoiceNumber(), string.Format("Full invoice #{0}", invoice.PrefixedInvoiceNumber())); // https://stripe.com/docs/api#create_charge try { var response = StripeHelper.MakeStripeApiRequest("https://api.stripe.com/v1/charges", "POST", requestParams, _settings); return(GetProcessPaymentResult(invoice, payment, response)); } catch (WebException ex) { return(GetProcessPaymentResult(invoice, payment, (HttpWebResponse)ex.Response)); } }
public IPaymentResult VoidPayment(IInvoice invoice, IPayment payment) { // Stripe does not seem to have a Void method, so we do a full refund string stripeChargeId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.StripeChargeId); if (!payment.Authorized || string.IsNullOrEmpty(stripeChargeId)) { return (new PaymentResult( Attempt <IPayment> .Fail(payment, new InvalidOperationException("Payment is not Authorized or Stripe charge id not present")), invoice, false)); } string url = string.Format("https://api.stripe.com/v1/charges/{0}/refunds", stripeChargeId); var response = StripeHelper.MakeStripeApiRequest(url, "POST", null, _settings); return(GetRefundPaymentResult(invoice, payment, response)); }
public IPaymentResult RefundPayment(IInvoice invoice, IPayment payment, decimal amount) { string stripeChargeId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.StripeChargeId); if (!payment.Authorized || string.IsNullOrEmpty(stripeChargeId)) { return (new PaymentResult( Attempt <IPayment> .Fail(payment, new InvalidOperationException("Payment is not Authorized or Stripe charge id not present")), invoice, false)); } string url = string.Format("https://api.stripe.com/v1/charges/{0}/refunds", stripeChargeId); var requestParams = new NameValueCollection(); requestParams.Add("amount", ConvertAmount(invoice, amount)); var response = StripeHelper.MakeStripeApiRequest(url, "POST", requestParams, _settings); return(GetRefundPaymentResult(invoice, payment, response)); }