当前位置: 首页>>代码示例>>C#>>正文


C# IInvoice.GetBillingAddress方法代码示例

本文整理汇总了C#中IInvoice.GetBillingAddress方法的典型用法代码示例。如果您正苦于以下问题:C# IInvoice.GetBillingAddress方法的具体用法?C# IInvoice.GetBillingAddress怎么用?C# IInvoice.GetBillingAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IInvoice的用法示例。


在下文中一共展示了IInvoice.GetBillingAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PerformTask

        /// <summary>
        /// Performs the task of applying taxes to the invoice.
        /// </summary>
        /// <param name="value">
        /// The <see cref="IInvoice"/>
        /// </param>
        /// <returns>
        /// The <see cref="Attempt"/>.
        /// </returns>
        public override Attempt<IInvoice> PerformTask(IInvoice value)
        {
            // if taxes are not to be applied, skip this step
            if (this.SalePreparation.ApplyTaxesToInvoice)
            {
                try
                {
                    // clear any current tax lines
                    var removers = value.Items.Where(x => x.LineItemType == LineItemType.Tax);
                    foreach (var remove in removers)
                    {
                        value.Items.Remove(remove);
                    }

                    IAddress taxAddress = null;
                    var shippingItems = value.ShippingLineItems().ToArray();
                    if (shippingItems.Any())
                    {
                        var shipment = shippingItems.First().ExtendedData.GetShipment<OrderLineItem>();
                        taxAddress = shipment.GetDestinationAddress();
                    }

                    taxAddress = taxAddress ?? value.GetBillingAddress();

                    this.SetTaxableSetting(value);
                    var taxes = value.CalculateTaxes(this.SalePreparation.MerchelloContext, taxAddress);
                    this.SetTaxableSetting(value, true);                    

                    var taxLineItem = taxes.AsLineItemOf<InvoiceLineItem>();

                    var currencyCode =
                        this.SalePreparation.MerchelloContext.Services.StoreSettingService.GetByKey(
                            Core.Constants.StoreSettingKeys.CurrencyCodeKey).Value;

                    taxLineItem.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, currencyCode);

                    value.Items.Add(taxLineItem);

                    return Attempt<IInvoice>.Succeed(value);
                }
                catch (Exception ex)
                {
                    return Attempt<IInvoice>.Fail(ex);
                }
            }

            return Attempt<IInvoice>.Succeed(value);
        }
开发者ID:Teknyc,项目名称:Merchello,代码行数:57,代码来源:ApplyTaxesToInvoiceTax.cs

示例2: 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;
        }
开发者ID:GaryLProthero,项目名称:Merchello,代码行数:38,代码来源:BraintreeApiRequestFactory.cs

示例3: CalculateTaxForInvoice

 /// <summary>
 /// Calculates the tax amount for an invoice
 /// </summary>
 /// <param name="invoice">The <see cref="IInvoice"/></param>
 /// <returns>The <see cref="ITaxCalculationResult"/></returns>
 /// <remarks>
 /// 
 /// Assumes the billing address of the invoice will be used for the taxation address
 /// 
 /// </remarks>
 public virtual ITaxCalculationResult CalculateTaxForInvoice(IInvoice invoice)
 {
     return CalculateTaxForInvoice(invoice, invoice.GetBillingAddress());
 }
开发者ID:ProNotion,项目名称:Merchello,代码行数:14,代码来源:TaxationGatewayMethodBase.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);
            }
        }
开发者ID:arknu,项目名称:Merchello,代码行数:76,代码来源:StripePaymentProcessor.cs

示例5: SetSagePayApiData

        //TODO: refactor away to a Service that wraps the SagePay kit horribleness
        private void SetSagePayApiData(IFormPayment request, IInvoice invoice, IPayment payment)
        {
            // Get Merchello data
            var billingAddress = invoice.GetBillingAddress();
            var shippingAddress = billingAddress;

            // Shipment - only use a shipping address if there is shipment info in the invoice
            var shipmentLineItem = invoice.ShippingLineItems().FirstOrDefault();
            if (shipmentLineItem != null)
            {
                var shipment = shipmentLineItem.ExtendedData.GetShipment<InvoiceLineItem>();
                shippingAddress = shipment.GetDestinationAddress();
            }
            
            // SagePay details
            request.VpsProtocol = Settings.ProtocolVersion;
            request.TransactionType = Settings.TransactionType;
            request.Vendor = Settings.VendorName;
            request.VendorTxCode = SagePayFormIntegration.GetNewVendorTxCode();
            request.Amount = payment.Amount;
            request.Currency = invoice.CurrencyCode();
            request.Description = "Goods from " + Settings.VendorName;
            
            // TODO:  Is there a basket summary I can access?  Or convert the Basket to a sagepay format

            // Set ReturnUrl and CancelUrl of SagePay request to SagePayApiController.
            Func<string, string> adjustUrl = (url) =>
            {
                if (!url.StartsWith("http")) url = GetWebsiteUrl() + (url[0] == '/' ? "" : "/") + url;
                url = url.Replace("{invoiceKey}", invoice.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                url = url.Replace("{paymentKey}", payment.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                return url;
            };

            request.SuccessUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/SuccessPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");
            request.FailureUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/AbortPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");

            // Billing details
            request.BillingSurname = billingAddress.TrySplitLastName();
            request.BillingFirstnames = billingAddress.TrySplitFirstName();
            request.BillingAddress1 = billingAddress.Address1;
            request.BillingAddress2 = billingAddress.Address2;
            request.BillingPostCode = billingAddress.PostalCode;
            request.BillingCity = billingAddress.Locality;
            request.BillingCountry = invoice.BillToCountryCode;
            request.CustomerEmail = billingAddress.Email;

            // Shipping details
            request.DeliverySurname = shippingAddress.TrySplitLastName();
            request.DeliveryFirstnames = shippingAddress.TrySplitFirstName();
            request.DeliveryAddress1 = shippingAddress.Address1;
            request.DeliveryCity = shippingAddress.Locality;
            request.DeliveryCountry = shippingAddress.CountryCode;
            request.DeliveryPostCode = shippingAddress.PostalCode;

            //Optional
            //request.CustomerName = cart.Billing.FirstNames + " " + cart.Billing.Surname;
            
            //request.VendorEmail = Settings.VendorEmail;
            //request.SendEmail = Settings.SendEmail;

            //request.EmailMessage = Settings.EmailMessage;
            //request.BillingAddress2 = billingAddress.Address2;
            //request.BillingPostCode = billingAddress.PostalCode;
            //request.BillingState = billingAddress.Region;
            //request.BillingPhone = billingAddress.Phone;
            //request.DeliveryAddress2 = shippingAddress.Address2;
            //request.DeliveryPostCode = shippingAddress.PostalCode;
            //request.DeliveryState = shippingAddress.Region;
            //request.DeliveryPhone = shippingAddress.Phone;

        }
开发者ID:chrisdaaaaay,项目名称:Merchello.Plugins.SagePay,代码行数:73,代码来源:SagePayFormPaymentProcessor.cs

示例6: 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 names = creditCard.CardholderName.Split(' ');

            // Declare a response
			Paymentech.Response response;

			// Create an authorize transaction
            var transaction = new Transaction(RequestType.NEW_ORDER_TRANSACTION);
			// Populate the required fields for the given transaction type. You can use’
			// the Paymentech Transaction Appendix to help you populate the transaction’

            transaction["OrbitalConnectionUsername"] = _settings.Username;
            transaction["OrbitalConnectionPassword"] = _settings.Password;
            /*
                * Message Types
                * MO – Mail Order transaction
                * RC – Recurring Payment
                * EC– eCommerce transaction
                * IV – IVR [PINLess Debit Only]
            */
			transaction["IndustryType"] = "EC";

            /*
                * Message Types
                * A – Authorization request
                * AC – Authorization and Mark for Capture
                * FC – Force-Capture request
                * R – Refund request
            */           
			transaction["MessageType"] = transactionMode == TransactionMode.Authorize ? "A" : "AC";

			transaction["MerchantID"] = _settings.MerchantId;
			transaction["BIN"] = _settings.Bin;
            
            // Credit Card Number
            transaction["AccountNum"] = creditCard.CardNumber.Replace(" ", "").Replace("-", "").Replace("|", "");

            transaction["OrderID"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

            transaction["Amount"] = string.Format("{0:0}", amount * 100);
            // Expiration date
            var creditCardExpMonth = creditCard.ExpireMonth;
            var creditCardExpYear = creditCard.ExpireYear.Length > 2
                ? creditCard.ExpireYear.Substring(2, 2)
                : creditCard.ExpireYear;

			transaction["Exp"] = creditCardExpMonth.PadLeft(2) + creditCardExpYear;

			transaction["AVSname"] = address.Name;
			transaction["AVSaddress1"] = address.Address1;  
			transaction["AVSaddress2"] = address.Address2;
			transaction["AVScity"] = address.Locality;
			transaction["AVSstate"] = address.Region;
			transaction["AVSzip"] = address.PostalCode;
			transaction["AVScountryCode"] = address.CountryCode;
			transaction["CardSecVal"] = creditCard.CardCode;

            transaction["TraceNumber"] = invoice.InvoiceNumber.ToString();

            if (string.IsNullOrEmpty(creditCard.CreditCardType))
            {
                creditCard.CreditCardType = GetCreditCardType(creditCard.CardNumber);
            }

            if (creditCard.CreditCardType.ToLower().Contains("visa") || creditCard.CreditCardType.ToLower().Contains("chase"))
            {
                transaction["CAVV"] = creditCard.AuthenticationVerification;

                // If no value for creditCard.CardCode, then CardSecValInd cannot be 1.  Send 2 or 9 instead
                if (string.IsNullOrEmpty(creditCard.CardCode))
                {
                    transaction["CardSecValInd"] = "9";
                }
                else
                {
                    transaction["CardSecValInd"] = "1";
                }
            }
            else if (creditCard.CreditCardType.ToLower().Contains("mastercard"))
            {
                transaction["AAV"] = creditCard.AuthenticationVerification;
                transaction["CardSecValInd"] = "";
            }
            transaction["AuthenticationECIInd"] = creditCard.AuthenticationVerificationEci;

            /*
                * CardSecValInd
                * 1 - Value is Present
//.........这里部分代码省略.........
开发者ID:drpeck,项目名称:Merchello,代码行数:101,代码来源:ChasePaymentProcessor.cs

示例7: VoidPayment

        public IPaymentResult VoidPayment(IInvoice invoice, IPayment payment)
        {
            var address = invoice.GetBillingAddress();

            // Declare a response
            Paymentech.Response response;

            // Create an authorize transaction
            var transaction = new Transaction(RequestType.VOID);

            var txRefNum = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber);


            if (!payment.Authorized || string.IsNullOrEmpty(txRefNum))
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new InvalidOperationException("Payment is not Authorized or TransactionCodes not present")), invoice, false);
            }

            transaction["OrbitalConnectionUsername"] = _settings.Username;
            transaction["OrbitalConnectionPassword"] = _settings.Password;

            transaction["MerchantID"] = _settings.MerchantId;
            transaction["BIN"] = _settings.Bin;

            transaction["OrderID"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);
            transaction["TxRefNum"] = txRefNum; 

            response = transaction.Process();

            // API Error
            if (response == null)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Chase Paymentech unknown error")), invoice, false);
            }

            if (response.Error)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
            }
            if (response.Declined)
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizeDeclinedResult, string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, response.TxRefNum);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1},{2}", response.AuthCode, response.ResponseCode, "NA"));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.Cvv2Result, string.Format("{0},{1}", response.CVV2RespCode, response.CVV2ResponseCode));

                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message))), invoice, false);
            }
            if (response.Approved)
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, response.TxRefNum);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1},{2}", response.AuthCode, response.ResponseCode, "NA"));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.Cvv2Result, string.Format("{0},{1}", response.CVV2RespCode, response.CVV2ResponseCode));
                
                payment.Collected = false;

                return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
            }

            var procStatus = "";
            if (response.XML != null)
            {
                var xml = XDocument.Parse(response.MaskedXML);
                procStatus = xml.Descendants("ProcStatus").First().Value;
            }

            if (!string.IsNullOrEmpty(procStatus) && procStatus == "0")
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.VoidProcStatus, procStatus);                                                               
                
                return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);  
            }
            return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
        }
开发者ID:drpeck,项目名称:Merchello,代码行数:76,代码来源:ChasePaymentProcessor.cs

示例8: GetMessage

		private MessageObject GetMessage(IInvoice invoice, IPayment payment)
		{
			if (invoice == null || payment == null)
				return null;
			
			MessageObject pay = _messageFactory.CreatePayInit();
			pay.SetAttribute(SaferPayConstants.MessageAttributes.AccountId, _settings.AccountId);
			pay.SetAttribute(SaferPayConstants.MessageAttributes.Amount, (invoice.Total * 100).ToString("##"));
			pay.SetAttribute(SaferPayConstants.MessageAttributes.Currency, invoice.Currency().CurrencyCode);
			pay.SetAttribute(SaferPayConstants.MessageAttributes.Description, _settings.Desciption);
			pay.SetAttribute(SaferPayConstants.MessageAttributes.OrderId, invoice.Key.ToString());

			// return urls
			pay.SetAttribute(SaferPayConstants.MessageAttributes.FailLink, GetWebsiteUrl(SaferPayConstants.Api.FailMethodName, invoice.Key, payment.Key));
			pay.SetAttribute(SaferPayConstants.MessageAttributes.BackLink, GetWebsiteUrl(SaferPayConstants.Api.BackMethodName, invoice.Key, payment.Key));
			pay.SetAttribute(SaferPayConstants.MessageAttributes.SuccessLink, GetWebsiteUrl(SaferPayConstants.Api.SuccessMethodName, invoice.Key, payment.Key));

			// todo: get them settings
			pay.SetAttribute(SaferPayConstants.MessageAttributes.NotifyAddress, _settings.NotifyAddress);
			pay.SetAttribute(SaferPayConstants.MessageAttributes.LangId, System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName);
			pay.SetAttribute(SaferPayConstants.MessageAttributes.ShowLanguages, "yes");

			if (invoice != null)
			{
				IAddress address = invoice.GetBillingAddress();
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Delivery, "no");
				pay.SetAttribute(SaferPayConstants.MessageAttributes.UserNotify, invoice.BillToEmail);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Company, invoice.BillToCompany);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Firstname, invoice.GetBillingAddress().TrySplitFirstName());
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Lastname, invoice.GetBillingAddress().TrySplitLastName());
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Street, invoice.BillToAddress1);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Zip, invoice.BillToPostalCode);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.City, invoice.BillToLocality);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Country, invoice.BillToCountryCode);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.EMail, invoice.BillToEmail);
				pay.SetAttribute(SaferPayConstants.MessageAttributes.Phone, invoice.BillToPhone);
			}

			return pay;
		}
开发者ID:ninjaonsafari,项目名称:Opten.Umbraco.Merchello.Plugins.Payment.SaferPay,代码行数:40,代码来源:SaferPayPaymentProcessor.cs

示例9: PriorAuthorizeCapturePayment

        /// <summary>
        /// Captures a previously authorized payment
        /// </summary>
        /// <param name="invoice">The invoice associated with the <see cref="IPayment"/></param>
        /// <param name="payment">The <see cref="IPayment"/> to capture</param>
        /// <returns>The <see cref="IPaymentResult"/></returns>
        public IPaymentResult PriorAuthorizeCapturePayment(IInvoice invoice, IPayment payment)
        {   
            var address = invoice.GetBillingAddress();

            // Declare a response
            Paymentech.Response response;

            // Create an authorize transaction
            var transaction = new Transaction(RequestType.MARK_FOR_CAPTURE_TRANSACTION);

            var txRefNum = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber);


            if (!payment.Authorized || string.IsNullOrEmpty(txRefNum))
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new InvalidOperationException("Payment is not Authorized or TransactionCodes not present")), invoice, false);
            }
            transaction["OrbitalConnectionUsername"] = _settings.Username;
            transaction["OrbitalConnectionPassword"] = _settings.Password;

            transaction["MerchantID"] = _settings.MerchantId;
            transaction["BIN"] = _settings.Bin;

            transaction["OrderID"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);
            transaction["TaxInd"] = "1";
            transaction["Tax"] = invoice.TotalTax().ToString(CultureInfo.InstalledUICulture);     
            transaction["PCOrderNum"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);
            transaction["PCDestZip"] = address.PostalCode;
            transaction["PCDestAddress1"] = address.Address1;
            transaction["PCDestAddress2"] = address.Address2;
            transaction["PCDestCity"] = address.Locality;
            transaction["PCDestState"] = address.Region;
            transaction["TxRefNum"] = txRefNum;                     

            response = transaction.Process();

            // API Error
            if (response == null)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Chase Paymentech unknown error")), invoice, false);
            }

            string approvalStatus = "";
            if (response.XML != null)
            {
                var xml = XDocument.Parse(response.MaskedXML);
                approvalStatus = xml.Descendants("ApprovalStatus").First().Value;
            }


            if (response.Error)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
            }
            if (response.Declined)
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizeDeclinedResult, string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, response.TxRefNum);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1},{2}", response.AuthCode, response.ResponseCode, approvalStatus));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.Cvv2Result, string.Format("{0},{1}", response.CVV2RespCode, response.CVV2ResponseCode));

                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message))), invoice, false);
            }
            if (response.Approved)
            {
                var txRefIdx = "";
                if (response.XML != null)
                {
                    var xml = XDocument.Parse(response.MaskedXML);
                    txRefIdx = xml.Descendants("TxRefIdx").First().Value;
                }

                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, response.TxRefNum);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceIndex, txRefIdx);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1},{2}", response.AuthCode, response.ResponseCode, approvalStatus));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.Cvv2Result, string.Format("{0},{1}", response.CVV2RespCode, response.CVV2ResponseCode));
                
                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}", response))), invoice, false);
        }
开发者ID:drpeck,项目名称:Merchello,代码行数:92,代码来源:ChasePaymentProcessor.cs

示例10: SetSagePayApiData

        //TODO: refactor away to a Service that wraps the SagePay kit horribleness
        private void SetSagePayApiData(IDirectPayment request, IInvoice invoice, IPayment payment, CreditCard creditCard)
        {
            // Get Merchello data
            //TODO - what if there is no shipping info?  e.g. Classes only - Get from billing?
            var shipmentLineItem = invoice.ShippingLineItems().FirstOrDefault();
            var shipment = shipmentLineItem.ExtendedData.GetShipment<InvoiceLineItem>();
            var shippingAddress = shipment.GetDestinationAddress();
            var billingAddress = invoice.GetBillingAddress(); 
            

            // Merchello info for callback
            //request.InvoiceKey = invoice.Key;
            //request.PayerId = invoice.Pa
            //request.PaymentKey = payment.Key
            
            // SagePay details
            request.VpsProtocol = Settings.ProtocolVersion;
            request.TransactionType = Settings.TransactionType;
            request.Vendor = Settings.VendorName;
            request.VendorTxCode = SagePayAPIIntegration.GetNewVendorTxCode();
            request.Amount = payment.Amount;
            request.Currency = invoice.CurrencyCode();
            request.Description = "Goods from " + Settings.VendorName;
            
            // TODO:  Is there a basket summary I can access?  Or convert the Basket to a sagepay format

            // Billing details
            request.BillingSurname = billingAddress.TrySplitLastName();
            request.BillingFirstnames = billingAddress.TrySplitFirstName();
            request.BillingAddress1 = billingAddress.Address1;
            request.BillingAddress2 = billingAddress.Address2;
            request.BillingPostCode = billingAddress.PostalCode;
            request.BillingCity = billingAddress.Locality;
            request.BillingCountry = invoice.BillToCountryCode;

            // Shipping details
            request.DeliverySurname = shippingAddress.TrySplitLastName();
            request.DeliveryFirstnames = shippingAddress.TrySplitFirstName();
            request.DeliveryAddress1 = shippingAddress.Address1;
            request.DeliveryCity = shippingAddress.Locality;
            request.DeliveryCountry = shippingAddress.CountryCode;
            request.DeliveryPostCode = shippingAddress.PostalCode;

            request.CardType = (CardType)Enum.Parse(typeof(CardType), creditCard.CreditCardType);
            request.CardHolder = creditCard.CardholderName;
            request.CardNumber = creditCard.CardNumber;
            request.ExpiryDate = creditCard.ExpireMonth + creditCard.ExpireYear;
            request.Cv2 = creditCard.CardCode;

            request.Apply3dSecure = 0;

            if (request.CardType == CardType.PAYPAL)
            {
                Func<string, string> adjustUrl = (url) =>
                {
                    if (!url.StartsWith("http")) url = GetWebsiteUrl() + (url[0] == '/' ? "" : "/") + url;
                    url = url.Replace("{invoiceKey}", invoice.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                    url = url.Replace("{paymentKey}", payment.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                    return url;
                };

                request.PayPalCallbackUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/PaypalCallback?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");
            }

            //Optional
            //request.CustomerName = cart.Billing.FirstNames + " " + cart.Billing.Surname;
            //request.CustomerEmail = customer.Email;
            //request.VendorEmail = Settings.VendorEmail;
            //request.SendEmail = Settings.SendEmail;

            //request.EmailMessage = Settings.EmailMessage;
            //request.BillingAddress2 = billingAddress.Address2;
            //request.BillingPostCode = billingAddress.PostalCode;
            //request.BillingState = billingAddress.Region;
            //request.BillingPhone = billingAddress.Phone;
            //request.DeliveryAddress2 = shippingAddress.Address2;
            //request.DeliveryPostCode = shippingAddress.PostalCode;
            //request.DeliveryState = shippingAddress.Region;
            //request.DeliveryPhone = shippingAddress.Phone;

        }
开发者ID:chrisdaaaaay,项目名称:Merchello.Plugins.SagePay,代码行数:82,代码来源:SagePayDirectPaymentProcessor.cs

示例11: 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);
        }
开发者ID:arknu,项目名称:Merchello,代码行数:71,代码来源:AuthorizeNetPaymentProcessor.cs

示例12: 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;
        }
开发者ID:cmgrey83,项目名称:Merchello.Plugin.Payment.Braintree,代码行数:33,代码来源:BraintreeApiRequestFactory.cs

示例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);
            }
        }
开发者ID:vonbv,项目名称:MerchelloStripeProvider,代码行数:51,代码来源:StripePaymentProcessor.cs

示例14: ProcessPayment

        protected override IPaymentResult ProcessPayment(IInvoice invoice, TransactionOption option, decimal amount, string paymentMethodNonce)
        {
            var payment = GatewayProviderService.CreatePayment(PaymentMethodType.CreditCard, amount, PaymentMethod.Key);

            payment.CustomerKey = invoice.CustomerKey;
            payment.Authorized = false;
            payment.Collected = false;
            payment.PaymentMethodName = "Braintree Transaction";
            payment.ExtendedData.SetValue(Braintree.Constants.ProcessorArguments.PaymentMethodNonce, paymentMethodNonce);

            var merchCustomer = invoice.Customer();

            if (merchCustomer == null)
            {
                var customerError = new NullReferenceException("A customer is not associated with the invoice.  Braintree vault transactions require a customer reference.");
                return new PaymentResult(Attempt<IPayment>.Fail(payment, customerError), invoice, false);
            }

            var result = BraintreeApiService.Transaction.Sale(invoice, paymentMethodNonce, merchCustomer, invoice.GetBillingAddress(), option);

            if (result.IsSuccess())
            {
                payment.ExtendedData.SetBraintreeTransaction(result.Target);

                if (option == TransactionOption.Authorize) payment.Authorized = true;
                if (option == TransactionOption.SubmitForSettlement)
                {
                    payment.Authorized = true;
                    payment.Collected = true;
                }

                return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
            }

            var error = new BraintreeApiException(result.Errors, result.Message);

            return new PaymentResult(Attempt<IPayment>.Fail(payment, error), invoice, false);
        }
开发者ID:GaryLProthero,项目名称:Merchello,代码行数:38,代码来源:BraintreeVaultTransactionPaymentGatewayMethod.cs

示例15: 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 names = creditCard.CardholderName.Split(' ');

            // Declare a response
			Paymentech.Response response;

			// Create an authorize transaction
            var transaction = new Transaction(RequestType.NEW_ORDER_TRANSACTION);
			// Populate the required fields for the given transaction type. You can use’
			// the Paymentech Transaction Appendix to help you populate the transaction’

            /*
                * Message Types
                * MO – Mail Order transaction
                * RC – Recurring Payment
                * EC– eCommerce transaction
                * IV – IVR [PINLess Debit Only]
            */
			transaction["IndustryType"] = "EC";

            /*
                * Message Types
                * A – Authorization request
                * AC – Authorization and Mark for Capture
                * FC – Force-Capture request
                * R – Refund request
            */           
			transaction["MessageType"] = transactionMode == TransactionMode.Authorize ? "A" : "AC";

			transaction["MerchantID"] = "041756";
			transaction["BIN"] = "000001";

            
            // Credit Card Number
            transaction["AccountNum"] = creditCard.CardNumber;

            transaction["OrderID"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

			transaction["Amount"] = amount.ToString("0.00", CultureInfo.InstalledUICulture);

            // Expiration date
			transaction["Exp"] = creditCard.ExpireMonth.PadLeft(2) + creditCard.ExpireYear;

			transaction["AVSname"] = address.Name;
			transaction["AVSaddress1"] = address.Address1;  
			transaction["AVSaddress2"] = address.Address2;
			transaction["AVScity"] = address.Locality;
			transaction["AVSstate"] = address.Region;
			transaction["AVSzip"] = address.PostalCode;
			transaction["AVScountryCode"] = address.CountryCode;
			transaction["CardSecVal"] = creditCard.CardCode;

            /*
                * CardSecValInd
                * 1 - Value is Present
                * 2 - Value on card but illegible
                * 9 - Cardholder states data not available              
            */
            transaction["CardSecValInd"] = "1";

            /*
                * CardSecValInd                               
                * A – Auto Generate the CustomerRefNum
                * S – Use CustomerRefNum Element            
            */
			transaction["CustomerProfileFromOrderInd"] = "A";

            /*
                * CustomerProfileOrderOverrideInd                   
                * NO No mapping to order data
                * OI Use <CustomerRefNum> for <OrderID> and <ECOrderNum> or <MailOrderNum>
                * OD Use <CustomerReferNum> for <Comments> 
                * OA Use <CustomerRefNum> for <OrderID> and <Comments>
            */
			transaction["CustomerProfileOrderOverrideInd"] = "NO";

            transaction["Comments"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

			response = transaction.Process();

            // API Error
            if (response == null)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Chase Paymentech unknown error")), invoice, false);
            }


            if (response.Error)
//.........这里部分代码省略.........
开发者ID:arknu,项目名称:Merchello,代码行数:101,代码来源:ChasePaymentProcessor.cs


注:本文中的IInvoice.GetBillingAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。