本文整理汇总了C#中IInvoice.PrefixedInvoiceNumber方法的典型用法代码示例。如果您正苦于以下问题:C# IInvoice.PrefixedInvoiceNumber方法的具体用法?C# IInvoice.PrefixedInvoiceNumber怎么用?C# IInvoice.PrefixedInvoiceNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInvoice
的用法示例。
在下文中一共展示了IInvoice.PrefixedInvoiceNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformAuthorizeCapturePayment
/// <summary>
/// Does the actual work of authorizing and capturing a payment
/// </summary>
/// <param name="invoice">The <see cref="IInvoice"/></param>
/// <param name="amount">The amount to capture</param>
/// <param name="args">Any arguments required to process the payment.</param>
/// <returns>The <see cref="IPaymentResult"/></returns>
protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args)
{
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, amount, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.PaymentMethodName = PaymentMethod.Name;
payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
payment.Collected = true;
payment.Authorized = true;
var po = args.AsPurchaseOrderFormData();
if (string.IsNullOrEmpty(po.PurchaseOrderNumber))
{
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Error Purchase Order Number is empty")), invoice, false);
}
invoice.PoNumber = po.PurchaseOrderNumber;
MerchelloContext.Current.Services.InvoiceService.Save(invoice);
GatewayProviderService.Save(payment);
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Cash payment", amount);
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0);
}
示例2: PerformAuthorizeCapturePayment
protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args)
{
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.Cash, amount, PaymentMethod.Key);
payment.PaymentMethodName = PaymentMethod.Name + " " + PaymentMethod.PaymentCode;
payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
payment.Collected = true;
payment.Authorized = true;
GatewayProviderService.Save(payment);
var appliedPayment = GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Cash payment", amount);
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, invoice.Total == amount);
}
示例3: PerformAuthorizePayment
/// <summary>
/// The perform authorize payment.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="args">
/// The args.
/// </param>
/// <returns>
/// The <see cref="IPaymentResult"/>.
/// </returns>
protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
{
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.CreditCard, invoice.Total, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.PaymentMethodName = PaymentMethod.Name;
payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
payment.Collected = false;
payment.Authorized = true;
GatewayProviderService.Save(payment);
// In this case, we want to do our own Apply Payment operation as the amount has not been collected -
// so we create an applied payment with a 0 amount. Once the payment has been "collected", another Applied Payment record will
// be created showing the full amount and the invoice status will be set to Paid.
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, string.Format("To show promise of a {0} payment", PaymentMethod.Name), 0);
return new PaymentResult(Attempt.Succeed(payment), invoice, false);
}
开发者ID:cmgrey83,项目名称:Merchello.Plugin.Payment.Braintree,代码行数:30,代码来源:BraintreeSubscriptionRecordPaymentMethod.cs
示例4: ProcessPayment
/// <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 = new NameValueCollection();
requestParams.Add("amount", ConvertAmount(invoice, amount));
requestParams.Add("currency", invoice.CurrencyCode());
if (transactionMode == TransactionMode.Authorize)
requestParams.Add("capture", "false");
requestParams.Add("card[number]", creditCard.CardNumber);
requestParams.Add("card[exp_month]", creditCard.ExpireMonth);
requestParams.Add("card[exp_year]", creditCard.ExpireYear);
requestParams.Add("card[cvc]", creditCard.CardCode);
requestParams.Add("card[name]", creditCard.CardholderName);
// Billing address
IAddress address = invoice.GetBillingAddress();
//requestParams.Add("receipt_email", address.Email); // note: this will send receipt email - maybe there should be a setting controlling if this is passed or not. Email could also be added to metadata
requestParams.Add("card[address_line1]", address.Address1);
requestParams.Add("card[address_line2]", address.Address2);
requestParams.Add("card[address_city]", address.Locality);
if (!string.IsNullOrEmpty(address.Region)) requestParams.Add("card[address_state]", address.Region);
requestParams.Add("card[address_zip]", address.PostalCode);
if (!string.IsNullOrEmpty(address.CountryCode))
requestParams.Add("card[address_country]", address.CountryCode);
requestParams.Add("metadata[invoice_number]", invoice.PrefixedInvoiceNumber());
requestParams.Add("description", string.Format("Full invoice #{0}", invoice.PrefixedInvoiceNumber()));
string postData =
requestParams.AllKeys.Aggregate("",
(current, key) => current + (key + "=" + HttpUtility.UrlEncode(requestParams[key]) + "&"))
.TrimEnd('&');
// https://stripe.com/docs/api#create_charge
try
{
var response = MakeStripeApiRequest("https://api.stripe.com/v1/charges", "POST", requestParams);
return GetProcessPaymentResult(invoice, payment, response);
}
catch (WebException ex)
{
return GetProcessPaymentResult(invoice, payment, (HttpWebResponse) ex.Response);
}
}
示例5: PerformAuthorizePayment
/// <summary>
/// Performs the AuthorizePayment operation.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="args">
/// The <see cref="ProcessorArgumentCollection"/>.
/// </param>
/// <returns>
/// The <see cref="IPaymentResult"/>.
/// </returns>
/// <remarks>
/// For the ExpressCheckout there is not technically an "Authorize" but we use this to start the checkout process and to
/// mark intent to pay before redirecting the customer to PayPal. e.g. This method is called after the customer has
/// clicked the Pay button, we then save the invoice and "Authorize" a payment setting the invoice status to Unpaid before redirecting.
/// IN this way, we have both an Invoice and a Payment (denoting the redirect). When the customer completes the purchase on PayPal sites
/// the payment will be used to perform a capture and the invoice status will be changed to Paid. In the event the customer cancels,
/// the invoice will either be voided or deleted depending on the configured setting.
/// Events are included in the controller handling the response to allow developers to override success and cancel redirect URLs.
/// </remarks>
protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
{
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.Redirect, invoice.Total, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.PaymentMethodName = PaymentMethod.Name;
payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
payment.Collected = false;
payment.Authorized = false; // this is technically not the authorization. We'll mark this in a later step.
// Have to save here to generate the payment key
GatewayProviderService.Save(payment);
// Now we want to get things setup for the ExpressCheckout
var record = this._paypalApiService.ExpressCheckout.SetExpressCheckout(invoice, payment);
payment.SavePayPalTransactionRecord(record);
// Have to save here to persist the record so it can be used in later processing.
GatewayProviderService.Save(payment);
// In this case, we want to do our own Apply Payment operation as the amount has not been collected -
// so we create an applied payment with a 0 amount. Once the payment has been "collected", another Applied Payment record will
// be created showing the full amount and the invoice status will be set to Paid.
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, string.Format("To show promise of a {0} payment via PayPal Express Checkout", PaymentMethod.Name), 0);
// if the ACK was success return a success IPaymentResult
if (record.Success)
{
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, false, record.SetExpressCheckout.RedirectUrl);
}
// In the case of a failure, package up the exception so we can bubble it up.
var ex = new PayPalApiException("PayPal Checkout Express initial response ACK was not Success");
if (record.SetExpressCheckout.ErrorTypes.Any()) ex.ErrorTypes = record.SetExpressCheckout.ErrorTypes;
return new PaymentResult(Attempt<IPayment>.Fail(payment, ex), invoice, false);
}
示例6: PerformAuthorizeCapturePayment
/// <summary>
/// The perform authorize capture payment.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="amount">
/// The amount.
/// </param>
/// <param name="args">
/// The args.
/// </param>
/// <returns>
/// The <see cref="IPaymentResult"/>.
/// </returns>
protected override IPaymentResult PerformAuthorizeCapturePayment(IInvoice invoice, decimal amount, ProcessorArgumentCollection args)
{
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.Cash, amount, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.PaymentMethodName = PaymentMethod.Name + " " + PaymentMethod.PaymentCode;
payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
payment.Collected = true;
payment.Authorized = true;
string transaction;
if (args.TryGetValue(Constants.ExtendedDataKeys.BraintreeTransaction, out transaction))
{
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.BraintreeTransaction, transaction);
}
GatewayProviderService.Save(payment);
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "Braintree subscription payment", amount);
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, CalculateTotalOwed(invoice).CompareTo(amount) <= 0);
}
开发者ID:cmgrey83,项目名称:Merchello.Plugin.Payment.Braintree,代码行数:36,代码来源:BraintreeSubscriptionRecordPaymentMethod.cs
示例7: ProcessPayment
/// <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)
{
var address = invoice.GetBillingAddress();
var form = GetInitialRequestForm(invoice.CurrencyCode());
var names = creditCard.CardholderName.Split(' ');
form.Add("x_type",
transactionMode == TransactionMode.Authorize ?
"AUTH_ONLY" : "AUTH_CAPTURE"
);
// Credit card information
form.Add("x_card_num", creditCard.CardNumber);
form.Add("x_exp_date", creditCard.ExpireMonth.PadLeft(2) + creditCard.ExpireYear);
form.Add("x_card_code", creditCard.CardCode);
form.Add("x_customer_ip", creditCard.CustomerIp);
// Billing address
form.Add("x_first_name", names.Count() > 1 ? names[0] : creditCard.CardholderName);
form.Add("x_last_name", names.Count() > 1 ? names[1] : string.Empty);
form.Add("x_email", address.Email);
if(!string.IsNullOrEmpty(address.Organization)) form.Add("x_company", address.Organization);
form.Add("x_address", address.Address1);
form.Add("x_city", address.Locality);
if(!string.IsNullOrEmpty(address.Region)) form.Add("x_state", address.Region);
form.Add("x_zip", address.PostalCode);
if(!string.IsNullOrEmpty(address.CountryCode)) form.Add("x_country", address.CountryCode);
// Invoice information
form.Add("x_amount", amount.ToString("0.00", CultureInfo.InstalledUICulture));
// maximum length 20 chars
form.Add("x_invoice_num", invoice.PrefixedInvoiceNumber());
form.Add("x_description", string.Format("Full invoice #{0}", invoice.PrefixedInvoiceNumber()));
var reply = GetAuthorizeNetReply(form);
// API Error
if(string.IsNullOrEmpty(reply)) return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Authorize.NET unknown error")), invoice, false);
var fields = reply.Split('|');
switch (fields[0])
{
case "3" :
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", reply))), invoice, false);
case "2" :
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizeDeclinedResult, string.Format("Declined ({0} : {1})", fields[2], fields[3]));
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Declined ({0} : {1})", fields[2], fields[3]))), invoice, false);
case "1" :
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1}", fields[6], fields[4]));
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionResult, string.Format("Approved ({0}: {1})", fields[2], fields[3]));
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, fields[5]);
payment.Authorized = true;
if (transactionMode == TransactionMode.AuthorizeAndCapture) payment.Collected = true;
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
}
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", reply))), invoice, false);
}
示例8: PerformAuthorizePayment
/// <summary>
/// Does the actual work of creating and processing the payment
/// </summary>
/// <param name="invoice">The <see cref="IInvoice"/></param>
/// <param name="args">Any arguments required to process the payment.</param>
/// <returns>The <see cref="IPaymentResult"/></returns>
protected override IPaymentResult PerformAuthorizePayment(IInvoice invoice, ProcessorArgumentCollection args)
{
var po = args.AsPurchaseOrderFormData();
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, invoice.Total, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.PaymentMethodName = PaymentMethod.Name;
payment.ReferenceNumber = PaymentMethod.PaymentCode + "-" + invoice.PrefixedInvoiceNumber();
payment.Collected = false;
payment.Authorized = true;
if (string.IsNullOrEmpty(po.PurchaseOrderNumber))
{
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Error Purchase Order Number is empty")), invoice, false);
}
invoice.PoNumber = po.PurchaseOrderNumber;
MerchelloContext.Current.Services.InvoiceService.Save(invoice);
GatewayProviderService.Save(payment);
// In this case, we want to do our own Apply Payment operation as the amount has not been collected -
// so we create an applied payment with a 0 amount. Once the payment has been "collected", another Applied Payment record will
// be created showing the full amount and the invoice status will be set to Paid.
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, string.Format("To show promise of a {0} payment", PaymentMethod.Name), 0);
//// If this were using a service we might want to store some of the transaction data in the ExtendedData for record
////payment.ExtendData
return new PaymentResult(Attempt.Succeed(payment), invoice, false);
}
示例9: CreateVaultTransactionRequest
/// <summary>
/// The create vault transaction request.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="paymentMethodToken">
/// The payment method token.
/// </param>
/// <param name="transactionOption">
/// The transaction option.
/// </param>
/// <returns>
/// The <see cref="TransactionRequest"/>.
/// </returns>
public TransactionRequest CreateVaultTransactionRequest(IInvoice invoice, string paymentMethodToken, TransactionOption transactionOption = TransactionOption.SubmitForSettlement)
{
var request = new TransactionRequest()
{
Amount = invoice.Total,
OrderId = invoice.PrefixedInvoiceNumber(),
PaymentMethodToken = paymentMethodToken,
BillingAddress = CreateAddressRequest(invoice.GetBillingAddress()),
Channel = Constants.TransactionChannel
};
if (transactionOption == TransactionOption.SubmitForSettlement)
{
request.Options = new TransactionOptionsRequest() { SubmitForSettlement = true };
}
return request;
}
示例10: Refund
/// <summary>
/// Refunds or partially refunds a payment.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="payment">
/// The payment.
/// </param>
/// <param name="amount">
/// The amount of the refund.
/// </param>
/// <returns>
/// The <see cref="PayPalExpressTransactionRecord"/>.
/// </returns>
public ExpressCheckoutResponse Refund(IInvoice invoice, IPayment payment, decimal amount)
{
var record = payment.GetPayPalTransactionRecord();
// Ensure the currency code
if (record.Data.CurrencyCode.IsNullOrWhiteSpace())
{
var ex = new PayPalApiException("CurrencyCode was not found in payment extended data PayPal transaction data record. Cannot perform refund.");
return _responseFactory.Build(ex);
}
// Ensure the transaction id
if (record.Data.CaptureTransactionId.IsNullOrWhiteSpace())
{
var ex = new PayPalApiException("CaptureTransactionId was not found in payment extended data PayPal transaction data record. Cannot perform refund.");
return _responseFactory.Build(ex);
}
// Get the decimal configuration for the current currency
var currencyCodeType = PayPalApiHelper.GetPayPalCurrencyCode(record.Data.CurrencyCode);
var basicAmountFactory = new PayPalBasicAmountTypeFactory(currencyCodeType);
ExpressCheckoutResponse result = null;
if (amount > payment.Amount) amount = payment.Amount;
try
{
var request = new RefundTransactionRequestType
{
InvoiceID = invoice.PrefixedInvoiceNumber(),
PayerID = record.Data.PayerId,
RefundSource = RefundSourceCodeType.DEFAULT,
Version = record.DoCapture.Version,
TransactionID = record.Data.CaptureTransactionId,
Amount = basicAmountFactory.Build(amount)
};
var wrapper = new RefundTransactionReq { RefundTransactionRequest = request };
var refundTransactionResponse = GetPayPalService().RefundTransaction(wrapper);
result = _responseFactory.Build(refundTransactionResponse, record.Data.Token);
}
catch (Exception ex)
{
result = _responseFactory.Build(ex);
}
return result;
}
示例11: VaultSale
/// <summary>
/// Performs a Braintree Transaction using a vaulted credit card.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="paymentMethodToken">
/// The payment method token.
/// </param>
/// <param name="customer">
/// The customer.
/// </param>
/// <param name="option">
/// The option.
/// </param>
/// <returns>
/// The <see cref="Result{Transaction}"/>.
/// </returns>
public Result<Transaction> VaultSale(
IInvoice invoice,
string paymentMethodToken,
TransactionOption option = TransactionOption.SubmitForSettlement)
{
var request = this.RequestFactory.CreateVaultTransactionRequest(invoice, paymentMethodToken, option);
LogHelper.Info<BraintreeTransactionApiService>(string.Format("Braintree Vault Transaction attempt ({0}) for Invoice {1}", option.ToString(), invoice.PrefixedInvoiceNumber()));
var attempt = this.TryGetApiResult(() => this.BraintreeGateway.Transaction.Sale(request));
return attempt.Success ? attempt.Result : null;
}
示例12: Sale
/// <summary>
/// Performs a Braintree sales transaction.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="paymentMethodNonce">
/// The payment method nonce.
/// </param>
/// <param name="customer">
/// The customer.
/// </param>
/// <param name="billingAddress">
/// The billing address.
/// </param>
/// <param name="shippingAddress">
/// The shipping address.
/// </param>
/// <param name="option">
/// The option.
/// </param>
/// <returns>
/// The <see cref="IPaymentResult"/>.
/// </returns>
public Result<Transaction> Sale(IInvoice invoice, string paymentMethodNonce, ICustomer customer, IAddress billingAddress, IAddress shippingAddress, TransactionOption option = TransactionOption.SubmitForSettlement)
{
var request = this.RequestFactory.CreateTransactionRequest(invoice, paymentMethodNonce, customer, option);
if (billingAddress != null) request.BillingAddress = this.RequestFactory.CreateAddressRequest(billingAddress);
if (shippingAddress != null) request.ShippingAddress = this.RequestFactory.CreateAddressRequest(shippingAddress);
LogHelper.Info<BraintreeTransactionApiService>(string.Format("Braintree Transaction attempt ({0}) for Invoice {1}", option.ToString(), invoice.PrefixedInvoiceNumber()));
var attempt = this.TryGetApiResult(() => this.BraintreeGateway.Transaction.Sale(request));
return attempt.Success ? attempt.Result : null;
}
示例13: ProcessPayment
/// <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);
}
}
示例14: CreateTransactionRequest
/// <summary>
/// Creates a <see cref="TransactionRequest"/>.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="paymentMethodNonce">
/// The payment Method Nonce.
/// </param>
/// <param name="customer">
/// The customer.
/// </param>
/// <param name="transactionOption">
/// The transaction Option.
/// </param>
/// <returns>
/// The <see cref="TransactionRequest"/>.
/// </returns>
public TransactionRequest CreateTransactionRequest(IInvoice invoice, string paymentMethodNonce, ICustomer customer = null, TransactionOption transactionOption = TransactionOption.Authorize)
{
var request = new TransactionRequest()
{
Amount = invoice.Total,
OrderId = invoice.PrefixedInvoiceNumber(),
PaymentMethodNonce = paymentMethodNonce,
BillingAddress = CreateAddressRequest(invoice.GetBillingAddress()),
Channel = Constants.TransactionChannel
};
if (customer != null) request.Customer = CreateCustomerRequest(customer);
if (transactionOption == TransactionOption.SubmitForSettlement)
{
request.Options = new TransactionOptionsRequest() { SubmitForSettlement = true };
}
return request;
}
示例15: Build
/// <summary>
/// Builds the <see cref="PaymentDetailsItemType"/>.
/// </summary>
/// <param name="invoice">
/// The invoice.
/// </param>
/// <param name="actionCode">
/// The <see cref="PaymentActionCodeType"/>.
/// </param>
/// <returns>
/// The <see cref="PaymentDetailsType"/>.
/// </returns>
public PaymentDetailsType Build(IInvoice invoice, PaymentActionCodeType actionCode)
{
// Get the decimal configuration for the current currency
var currencyCodeType = PayPalApiHelper.GetPayPalCurrencyCode(invoice.CurrencyCode);
var basicAmountFactory = new PayPalBasicAmountTypeFactory(currencyCodeType);
// Get the tax total
var itemTotal = basicAmountFactory.Build(invoice.TotalItemPrice());
var shippingTotal = basicAmountFactory.Build(invoice.TotalShipping());
var taxTotal = basicAmountFactory.Build(invoice.TotalTax());
var invoiceTotal = basicAmountFactory.Build(invoice.Total);
var items = BuildPaymentDetailsItemTypes(invoice.ProductLineItems(), basicAmountFactory);
var paymentDetails = new PaymentDetailsType
{
PaymentDetailsItem = items.ToList(),
ItemTotal = itemTotal,
TaxTotal = taxTotal,
ShippingTotal = shippingTotal,
OrderTotal = invoiceTotal,
PaymentAction = actionCode,
InvoiceID = invoice.PrefixedInvoiceNumber()
};
// ShipToAddress
if (invoice.ShippingLineItems().Any())
{
var addressTypeFactory = new PayPalAddressTypeFactory();
paymentDetails.ShipToAddress = addressTypeFactory.Build(invoice.GetShippingAddresses().FirstOrDefault());
}
return paymentDetails;
}