コード例 #1
0
        /// <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;
        }
コード例 #2
0
        public bool Authorize(Transaction t, HotcakesApplication app)
        {
            try
            {
                var ppAPI = PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore);

                if (t.PreviousTransactionNumber != null)
                {
                    var OrderNumber = t.MerchantInvoiceNumber + Guid.NewGuid();

                    PaymentActionCodeType mode = PaymentActionCodeType.Authorization;
                    if (!app.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    var paymentResponse = ppAPI.DoExpressCheckoutPayment(t.PreviousTransactionNumber,
                        t.PreviousTransactionAuthCode,
                        t.Amount.ToString("N", CultureInfo.InvariantCulture),
                        mode,
                        PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency),
                        OrderNumber);

                    if (paymentResponse.Ack == AckCodeType.Success ||
                        paymentResponse.Ack == AckCodeType.SuccessWithWarning)
                    {
                        var paymentInfo = paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0];

                        t.Result.Succeeded = true;
                        t.Result.ReferenceNumber = paymentInfo.TransactionID;
                        t.Result.ResponseCode = "OK";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment Authorized Successfully.";
                        return true;
                    }
                    t.Result.Succeeded = false;
                    t.Result.Messages.Add(new Message("PayPal Express Payment Authorization Failed.", string.Empty,
                        MessageType.Error));
                    foreach (var ppError in paymentResponse.Errors)
                    {
                        t.Result.Messages.Add(new Message(ppError.LongMessage, ppError.ErrorCode, MessageType.Error));
                    }
                    return false;
                }
            }
            catch (Exception ex)
            {
                HandleException(t, ex);
            }

            return false;
        }
コード例 #3
0
        /// <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() - invoice.TotalDiscounts());
            var shippingTotal = basicAmountFactory.Build(invoice.TotalShipping());
            var taxTotal      = basicAmountFactory.Build(invoice.TotalTax());
            var invoiceTotal  = basicAmountFactory.Build(invoice.Total);

            var items = BuildPaymentDetailsItemTypes(invoice.ProductLineItems(), basicAmountFactory).ToList();

            if (invoice.DiscountLineItems().Any())
            {
                var discounts = BuildPaymentDetailsItemTypes(invoice.DiscountLineItems(), basicAmountFactory, true);
                items.AddRange(discounts);
            }

            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);
        }
コード例 #4
0
ファイル: PaypalAPI.cs プロジェクト: mikeshane/MerchantTribe
        public SetExpressCheckoutResponseType SetExpressCheckout(string paymentAmount, string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, string invoiceId)
        {
            // Create the request object
            SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();

            // Create the request details object
            pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            pp_request.SetExpressCheckoutRequestDetails.PaymentAction          = paymentAction;
            pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;
            pp_request.SetExpressCheckoutRequestDetails.InvoiceID  = invoiceId;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value      = paymentAmount;

            pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
            pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;

            return((SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request));
        }
コード例 #5
0
        protected SetExpressCheckoutResponseType ECSetExpressCheckoutCode(string paymentAmount, string returnURL, string cancelURL,
            PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType)
        {
            CallerServices caller = CreateCaller();

            var pp_request = new SetExpressCheckoutRequestType()
            {
                Version = "51.0",
                SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType()
                {
                    PaymentAction = paymentAction,
                    PaymentActionSpecified = true,
                    OrderTotal = new BasicAmountType()
                    {
                        currencyID = currencyCodeType,
                        Value = paymentAmount
                    },
                    CancelURL = cancelURL,
                    ReturnURL = returnURL,
                }
            };

            return (SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request);
        }
コード例 #6
0
        private PaymentDetailsType GetPaypalPaymentDetail(CurrencyCodeType currency, PaymentActionCodeType paymentAction)
        {
            var paymentDetails = new PaymentDetailsType { PaymentAction = paymentAction };
            decimal itemTotal;
            paymentDetails.PaymentDetailsItem.AddRange(GetPaypalPaymentDetailsItemTypes(currency, out itemTotal));
            paymentDetails.ItemTotal = new BasicAmountType(currency, FormatMoney(itemTotal));
            paymentDetails.ShippingTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.ShippingTotal));
            paymentDetails.HandlingTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.HandlingTotal));
            paymentDetails.TaxTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.TaxTotal));
            paymentDetails.OrderTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.Total));

            var shippingDiscount = Ch.Cart.OrderForms.SelectMany(c => c.Shipments).Sum(c => c.ShippingDiscountAmount);
            if (shippingDiscount > 0)
            {
                paymentDetails.ShippingDiscount = new BasicAmountType(currency, FormatMoney(-shippingDiscount));
            }
            return paymentDetails;
        }
コード例 #7
0
ファイル: PaypalAPI.cs プロジェクト: appliedi/MerchantTribe
        public DoDirectPaymentResponseType DoDirectPayment(string paymentAmount, string buyerBillingLastName, string buyerBillingFirstName, string buyerShippingLastName, string buyerShippingFirstName, string buyerBillingAddress1, string buyerBillingAddress2, string buyerBillingCity, string buyerBillingState, string buyerBillingPostalCode, CountryCodeType buyerBillingCountryCode, string creditCardType, string creditCardNumber, string CVV2, int expMonth, int expYear, PaymentActionCodeType paymentAction, string ipAddress, string buyerShippingAddress1, string buyerShippingAddress2, string buyerShippingCity, string buyerShippingState, string buyerShippingPostalCode, CountryCodeType buyerShippingCountryCode, string invoiceId)
        {
            // Create the request object
            DoDirectPaymentRequestType pp_Request = new DoDirectPaymentRequestType();

            // Create the request details object
            pp_Request.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();

            pp_Request.DoDirectPaymentRequestDetails.IPAddress = ipAddress;
            pp_Request.DoDirectPaymentRequestDetails.MerchantSessionId = "";
            pp_Request.DoDirectPaymentRequestDetails.PaymentAction = paymentAction;            
            pp_Request.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = creditCardNumber;
            switch (creditCardType)
            {
                case "Visa":
                    pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa;
                    break;
                case "MasterCard":
                    pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard;
                    break;
                case "Discover":
                    pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Discover;
                    break;
                case "Amex":
                    pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Amex;
                    break;
            }
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CVV2 = CVV2;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = expMonth;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYear = expYear;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonthSpecified = true;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYearSpecified = true;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Payer = "";
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerID = "";
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerStatus = PayPalUserStatusCodeType.unverified;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerCountry = CountryCodeType.US;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = buyerBillingAddress1;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = buyerBillingAddress2;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = buyerBillingCity;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = buyerBillingState;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = buyerBillingPostalCode;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = buyerBillingCountryCode;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;

            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress = new AddressType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name = buyerShippingFirstName + " " + buyerShippingLastName;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1 = buyerShippingAddress1;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street2 = buyerShippingAddress2;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName = buyerShippingCity;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince = buyerShippingState;            
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode = buyerShippingPostalCode;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country = buyerShippingCountryCode;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = buyerBillingFirstName;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = buyerBillingLastName;
            
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.InvoiceID = invoiceId;
            
            // NOTE: The only currency supported by the Direct Payment API at this time is US dollars (USD).
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = paymentAmount;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ButtonSource = "BVCommerce_Cart_DP_US";
            return (DoDirectPaymentResponseType)caller.Call("DoDirectPayment", pp_Request);
        }
コード例 #8
0
ファイル: PaypalAPI.cs プロジェクト: appliedi/MerchantTribe
        public SetExpressCheckoutResponseType SetExpressCheckout(string paymentAmount, string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, String name, String countryISOCode, String street1, String street2, String city, String region, String postalCode, String phone, string invoiceId)
        {
            // Create the request object
            SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();

            // Create the request details object
            pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
            pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;

            pp_request.SetExpressCheckoutRequestDetails.AddressOverride = "1";
            pp_request.SetExpressCheckoutRequestDetails.InvoiceID = invoiceId;

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;

            pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
            pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;
            
            pp_request.SetExpressCheckoutRequestDetails.Address = new AddressType();            
            pp_request.SetExpressCheckoutRequestDetails.Address.AddressStatusSpecified = false;
            pp_request.SetExpressCheckoutRequestDetails.Address.AddressOwnerSpecified = false;

            pp_request.SetExpressCheckoutRequestDetails.Address.Street1 = street1;
            pp_request.SetExpressCheckoutRequestDetails.Address.Street2 = street2;
            pp_request.SetExpressCheckoutRequestDetails.Address.CityName = city;
            pp_request.SetExpressCheckoutRequestDetails.Address.StateOrProvince = region;
            pp_request.SetExpressCheckoutRequestDetails.Address.PostalCode = postalCode;
            pp_request.SetExpressCheckoutRequestDetails.Address.CountrySpecified = true;
            pp_request.SetExpressCheckoutRequestDetails.Address.Country = GetCountryCode(countryISOCode);                        
            pp_request.SetExpressCheckoutRequestDetails.Address.Phone = phone;
            pp_request.SetExpressCheckoutRequestDetails.Address.Name = name;                        
            return (SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request);
        }
コード例 #9
0
 /**
  	  * Constructor with arguments
  	  */
 public DoReferenceTransactionRequestDetailsType(string ReferenceID, PaymentActionCodeType? PaymentAction, PaymentDetailsType PaymentDetails)
 {
     this.ReferenceID = ReferenceID;
     this.PaymentAction = PaymentAction;
     this.PaymentDetails = PaymentDetails;
 }
コード例 #10
0
        public override bool Execute(OrderTaskContext context)
        {
            if (context.Inputs["Mode"] != null)
            {
                if (context.Inputs["Mode"].Value == "PaypalExpress")
                {
                    if (context.MTApp.CurrentRequestContext.RoutingContext.HttpContext != null)
                    {
                        PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(context.MTApp.CurrentStore);
                        try {
                            string cartReturnUrl = string.Empty;
                            string cartCancelUrl = string.Empty;
                            if (context.MTApp.CurrentRequestContext != null)
                            {
                                cartReturnUrl = context.MTApp.CurrentRequestContext.CurrentStore.RootUrlSecure() + "paypalexpresscheckout";
                                cartCancelUrl = context.MTApp.CurrentRequestContext.CurrentStore.RootUrlSecure() + "checkout";
                            }

                            EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
                            EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

                            SetExpressCheckoutResponseType expressResponse;
                            PaymentActionCodeType          mode = PaymentActionCodeType.Authorization;

                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                            {
                                mode = PaymentActionCodeType.Order;
                            }
                            else
                            {
                                mode = PaymentActionCodeType.Sale;
                            }

                            // Accelerated boarding
                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.UserName.Trim().Length < 1)
                            {
                                mode = PaymentActionCodeType.Sale;
                            }


                            bool addressSupplied = false;
                            if (context.Inputs["AddressSupplied"] != null)
                            {
                                if (context.Inputs["AddressSupplied"].Value == "1")
                                {
                                    addressSupplied = true;
                                    context.Order.CustomProperties.Add("bvsoftware", "PaypalAddressOverride", "1");
                                }
                            }

                            string amountToPayPal = context.Order.TotalOrderBeforeDiscounts.ToString("N", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));

                            if (addressSupplied)
                            {
                                Contacts.Address address = context.Order.ShippingAddress;

                                MerchantTribe.Web.Geography.Country country = MerchantTribe.Web.Geography.Country.FindByBvin(address.CountryBvin);
                                if (country != null)
                                {
                                    expressResponse = ppAPI.SetExpressCheckout(
                                        amountToPayPal,
                                        cartReturnUrl,
                                        cartCancelUrl,
                                        mode,
                                        PayPalAPI.GetCurrencyCodeType(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Currency),
                                        address.FirstName + " " + address.LastName,
                                        country.IsoCode,
                                        address.Line1,
                                        address.Line2,
                                        address.City,
                                        address.RegionBvin,
                                        address.PostalCode,
                                        address.Phone,
                                        context.Order.OrderNumber + System.Guid.NewGuid().ToString());
                                    if (expressResponse == null)
                                    {
                                        EventLog.LogEvent("PayPal Express Checkout", "Express Response Was Null!", EventLogSeverity.Error);
                                    }
                                }
                                else
                                {
                                    EventLog.LogEvent("StartPaypalExpressCheckout", "Country with bvin " + address.CountryBvin + " was not found.", EventLogSeverity.Error);
                                    return(false);
                                }
                            }
                            else
                            {
                                expressResponse = ppAPI.SetExpressCheckout(amountToPayPal,
                                                                           cartReturnUrl,
                                                                           cartCancelUrl,
                                                                           mode,
                                                                           PayPalAPI.GetCurrencyCodeType(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Currency),
                                                                           context.Order.OrderNumber + System.Guid.NewGuid().ToString());
                                if (expressResponse == null)
                                {
                                    EventLog.LogEvent("PayPal Express Checkout", "Express Response2 Was Null!", EventLogSeverity.Error);
                                }
                            }

                            if (expressResponse.Ack == AckCodeType.Success || expressResponse.Ack == AckCodeType.SuccessWithWarning)
                            {
                                context.Order.ThirdPartyOrderId = expressResponse.Token;

                                // Recording of this info is handled on the paypal express
                                // checkout page instead of here.
                                //Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order);
                                //payManager.PayPalExpressAddInfo(context.Order.TotalGrand, expressResponse.Token);

                                EventLog.LogEvent("PayPal Express Checkout", "Response SUCCESS", EventLogSeverity.Information);

                                Orders.OrderNote note = new Orders.OrderNote();
                                note.IsPublic = false;
                                note.Note     = "Paypal Order Accepted With Paypal Order Number: " + expressResponse.Token;
                                context.Order.Notes.Add(note);
                                if (context.MTApp.OrderServices.Orders.Update(context.Order))
                                {
                                    if (string.Compare(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
                                    {
                                        context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + expressResponse.Token, true);
                                    }
                                    else
                                    {
                                        context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + expressResponse.Token, true);
                                    }
                                }
                                return(true);
                            }
                            else
                            {
                                foreach (ErrorType ppError in expressResponse.Errors)
                                {
                                    context.Errors.Add(new WorkflowMessage(ppError.ErrorCode, ppError.ShortMessage, true));

                                    //create a note to save the paypal error info onto the order
                                    Orders.OrderNote note = new Orders.OrderNote();
                                    note.IsPublic = false;
                                    note.Note     = "Paypal error number: " + ppError.ErrorCode + " Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage;
                                    context.Order.Notes.Add(note);

                                    EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to SetExpressCheckout: Total=" + string.Format("{0:c}", context.Order.TotalOrderBeforeDiscounts) + " Cart Return Url: " + cartReturnUrl + " Cart Cancel Url: " + cartCancelUrl, EventLogSeverity.Error);
                                }
                                context.Errors.Add(new WorkflowMessage("Paypal checkout error", Content.SiteTerms.GetTerm(Content.SiteTermIds.PaypalCheckoutCustomerError), true));
                                return(false);
                            }
                        }
                        catch (Exception ex) {
                            EventLog.LogEvent("Paypal Express Checkout", "Exception occurred during call to Paypal: " + ex.ToString(), EventLogSeverity.Error);
                            context.Errors.Add(new WorkflowMessage("Paypal checkout error", Content.SiteTerms.GetTerm(Content.SiteTermIds.PaypalCheckoutCustomerError), true));
                            return(false);
                        }
                        finally {
                            ppAPI = null;
                        }
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }

            return(false);
        }
コード例 #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext CurrContext = HttpContext.Current;

        // Create the DoExpressCheckoutPaymentResponseType object
        DoExpressCheckoutPaymentResponseType responseDoExpressCheckoutPaymentResponseType = new DoExpressCheckoutPaymentResponseType();

        try
        {
            // Create the DoExpressCheckoutPaymentReq object
            DoExpressCheckoutPaymentReq doExpressCheckoutPayment = new DoExpressCheckoutPaymentReq();
            DoExpressCheckoutPaymentRequestDetailsType doExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
            // The timestamped token value that was returned in the
            // `SetExpressCheckout` response and passed in the
            // `GetExpressCheckoutDetails` request.
            doExpressCheckoutPaymentRequestDetails.Token = (string)(Session["EcToken"]);
            // Unique paypal buyer account identification number as returned in
            // `GetExpressCheckoutDetails` Response
            doExpressCheckoutPaymentRequestDetails.PayerID = (string)(Session["PayerId"]);

            // # Payment Information
            // list of information about the payment
            List <PaymentDetailsType> paymentDetailsList = new List <PaymentDetailsType>();
            // information about the payment
            PaymentDetailsType    paymentDetails      = new PaymentDetailsType();
            CurrencyCodeType      currency_code_type  = (CurrencyCodeType)(Session["currency_code_type"]);
            PaymentActionCodeType payment_action_type = (PaymentActionCodeType)(Session["payment_action_type"]);
            //Pass the order total amount which was already set in session
            string          total_amount = (string)(Session["Total_Amount"]);
            BasicAmountType orderTotal   = new BasicAmountType(currency_code_type, total_amount);
            paymentDetails.OrderTotal    = orderTotal;
            paymentDetails.PaymentAction = payment_action_type;

            //BN codes to track all transactions
            paymentDetails.ButtonSource = BNCode;

            // Unique identifier for the merchant.
            SellerDetailsType sellerDetails = new SellerDetailsType();
            sellerDetails.PayPalAccountID = (string)(Session["SellerEmail"]);
            paymentDetails.SellerDetails  = sellerDetails;

            paymentDetailsList.Add(paymentDetails);
            doExpressCheckoutPaymentRequestDetails.PaymentDetails = paymentDetailsList;

            DoExpressCheckoutPaymentRequestType doExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType(doExpressCheckoutPaymentRequestDetails);
            doExpressCheckoutPayment.DoExpressCheckoutPaymentRequest = doExpressCheckoutPaymentRequest;
            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
            // # API call
            // Invoke the DoExpressCheckoutPayment method in service wrapper object
            responseDoExpressCheckoutPaymentResponseType = service.DoExpressCheckoutPayment(doExpressCheckoutPayment);
            if (responseDoExpressCheckoutPaymentResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "DoExpressCheckoutPayment API Operation - ";
                acknowledgement += responseDoExpressCheckoutPaymentResponseType.Ack.ToString();
                //logger.Info(acknowledgement + "\n");
                System.Diagnostics.Debug.WriteLine(acknowledgement + "\n");
                // # Success values
                if (responseDoExpressCheckoutPaymentResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Transaction identification number of the transaction that was
                    // created.
                    // This field is only returned after a successful transaction
                    // for DoExpressCheckout has occurred.
                    if (responseDoExpressCheckoutPaymentResponseType.DoExpressCheckoutPaymentResponseDetails.PaymentInfo != null)
                    {
                        IEnumerator <PaymentInfoType> paymentInfoIterator = responseDoExpressCheckoutPaymentResponseType.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.GetEnumerator();
                        while (paymentInfoIterator.MoveNext())
                        {
                            PaymentInfoType paymentInfo = paymentInfoIterator.Current;
                            //logger.Info("Transaction ID : " + paymentInfo.TransactionID + "\n");

                            Session["Transaction_Id"]       = paymentInfo.TransactionID;
                            Session["Transaction_Type"]     = paymentInfo.TransactionType;
                            Session["Payment_Status"]       = paymentInfo.PaymentStatus;
                            Session["Payment_Type"]         = paymentInfo.PaymentType;
                            Session["Payment_Total_Amount"] = paymentInfo.GrossAmount.value;

                            System.Diagnostics.Debug.WriteLine("Transaction ID : " + paymentInfo.TransactionID + "\n");
                        }
                    }
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseDoExpressCheckoutPaymentResponseType.Errors;
                    string           errorMessage  = "";
                    foreach (ErrorType error in errorMessages)
                    {
                        //logger.Debug("API Error Message : " + error.LongMessage);
                        System.Diagnostics.Debug.WriteLine("API Error Message : " + error.LongMessage + "\n");
                        errorMessage = errorMessage + error.LongMessage;
                    }
                    //Redirect to error page in case of any API errors
                    CurrContext.Items.Add("APIErrorMessage", errorMessage);
                    Server.Transfer("~/Response.aspx");
                }
            }
        }
        catch (System.Exception ex)
        {
            // Log the exception message
            //logger.Debug("Error Message : " + ex.Message);
            System.Diagnostics.Debug.WriteLine("Error Message : " + ex.Message);
        }
    }
コード例 #12
0
		private PaymentDetailsType GetPaypalPaymentDetail(string currency, PaymentActionCodeType paymentAction, PaymentIn payment)
		{
			var paymentDetails = new PaymentDetailsType { PaymentAction = paymentAction };
			paymentDetails.OrderTotal = new BasicAmountType(GetPaypalCurrency(currency), FormatMoney(payment.Sum));
            paymentDetails.ButtonSource = "Virto_SP";

            return paymentDetails;
		}
コード例 #13
0
 public new SetExpressCheckoutResponseType ECSetExpressCheckoutCode(string paymentAmount, string returnURL, string cancelURL,
     PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType)
 {
     return base.ECSetExpressCheckoutCode(paymentAmount, returnURL, cancelURL, paymentAction, currencyCodeType);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext CurrContext = HttpContext.Current;

        // Create the SetExpressCheckoutResponseType object
        SetExpressCheckoutResponseType responseSetExpressCheckoutResponseType = new SetExpressCheckoutResponseType();

        try
        {
            // Check if the EC methos is shorcut or mark
            string ecMethod = "";
            if (Request.QueryString["ExpressCheckoutMethod"] != null)
            {
                ecMethod = Request.QueryString["ExpressCheckoutMethod"];
            }
            else if ((string)(Session["ExpressCheckoutMethod"]) != null)
            {
                ecMethod = (string)(Session["ExpressCheckoutMethod"]);
            }
            string item_name     = "";
            string item_id       = "";
            string item_desc     = "";
            string item_quantity = "";
            string item_amount   = "";
            //string tax_amount = "";
            //string shipping_amount = "";
            //string handling_amount = "";
            //string shipping_discount_amount = "";
            //string insurance_amount = "";
            string total_amount  = "";
            string currency_code = "";
            string payment_type  = "";
            string roundedtotal  = "";
            string roundeditmamt = "";

            // From Marck EC Page
            //string shipping_rate = "";
            string first_name  = "";
            string last_name   = "";
            string street1     = "";
            string street2     = "";
            string city        = "";
            string state       = "";
            string postal_code = "";
            string country     = "";
            string phone       = "";
            //Double new_total_rate = 0.00;
            AddressType shipToAddress = new AddressType();
            if (ecMethod != null && ecMethod == "ShorcutExpressCheckout")
            {
                // Get parameters from index page (shorcut express checkout)
                item_name     = Request.Form["item_name"];
                item_id       = Request.Form["item_id"];
                item_desc     = Request.Form["item_desc"];
                item_quantity = Request.Form["item_quantity"];
                item_amount   = Request.Form["item_amount"];

                total_amount            = Request.Form["total_amount"];
                currency_code           = Request.Form["currency_code_type"];
                payment_type            = Request.Form["payment_type"];
                Session["Total_Amount"] = total_amount;

                roundeditmamt = (Math.Round(double.Parse(item_amount), 2)).ToString();
                roundedtotal  = (Math.Round(double.Parse(total_amount), 2)).ToString();
            }
            else if (ecMethod != null && ecMethod == "MarkExpressCheckout")
            {
                // Get parameters from mark ec page
                //shipping_rate = Request.Form["shipping_method"].ToString();

                item_name     = Request.Form["item_name"];
                item_id       = Request.Form["item_id"];
                item_desc     = Request.Form["item_desc"];
                item_quantity = Request.Form["item_quantity"];
                item_amount   = Request.Form["item_amount"];
                //tax_amount = Request.Form["tax_amount"];
                //shipping_amount = Request.Form["shipping_amount"];
                //handling_amount = Request.Form["handling_amount"];
                //shipping_discount_amount = Request.Form["shipping_discount_amount"];
                //insurance_amount = Request.Form["insurance_amount"];
                total_amount  = Request.Form["total_amount"];
                currency_code = Request.Form["currency_code"];
                payment_type  = Request.Form["payment_type"];

                first_name  = Request.Form["FIRST_NAME"];
                last_name   = Request.Form["LAST_NAME"];
                street1     = Request.Form["STREET_1"];
                street2     = Request.Form["STREET_2"];
                city        = Request.Form["CITY"];
                state       = Request.Form["STATE"];
                postal_code = Request.Form["POSTAL_CODE"];
                country     = Request.Form["COUNTRY"];
                phone       = Request.Form["PHONE"];

                roundeditmamt = (Math.Round(double.Parse(item_amount), 2)).ToString();
                roundedtotal  = (Math.Round(double.Parse(total_amount), 2)).ToString();

                // Set the details of new shipping address
                //shipToAddress.Name = first_name + " " + last_name;
                //shipToAddress.Street1 = street1;
                //if (!street2.Equals(""))
                //{
                //    shipToAddress.Street2 = street2;
                //}
                //shipToAddress.CityName = city;
                //shipToAddress.StateOrProvince = state;
                //string countrycode = country;
                //CountryCodeType countryCodeType = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), countrycode, true);
                //shipToAddress.Country = countryCodeType;
                //shipToAddress.PostalCode = postal_code;
                //if (!phone.Equals(""))
                //{
                //    shipToAddress.Phone = phone;
                //}

                //Double total_rate = Convert.ToDouble(total_amount);
                //Double old_shipping_rate = Convert.ToDouble(shipping_amount);
                //Double new_shipping_rate = Convert.ToDouble(shipping_rate);

                // Calculate new order total based on shipping method selected
                //new_total_rate = total_rate - old_shipping_rate + new_shipping_rate;
                //Session["Total_Amount"] = new_total_rate.ToString();
                //total_amount = new_total_rate.ToString();
                //shipping_amount = new_shipping_rate.ToString();
            }

            Session["SellerEmail"] = SellerEmail;
            CurrencyCodeType currencyCode_Type = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), currency_code, true);
            Session["currency_code_type"] = currencyCode_Type;
            PaymentActionCodeType payment_ActionCode_Type = (PaymentActionCodeType)Enum.Parse(typeof(PaymentActionCodeType), payment_type, true);
            Session["payment_action_type"] = payment_ActionCode_Type;
            // SetExpressCheckoutRequestDetailsType object
            SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            // (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal.
            setExpressCheckoutRequestDetails.ReturnURL = ReturnUrl;
            //(Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you
            setExpressCheckoutRequestDetails.CancelURL = CancelUrl;
            // A URL to your logo image. Use a valid graphics format, such as .gif, .jpg, or .png
            setExpressCheckoutRequestDetails.cppLogoImage = LogoUrl;
            // To display the border in your principal identifying color, set the "cppCartBorderColor" parameter to the 6-digit hexadecimal value of that color
            // setExpressCheckoutRequestDetails.cppCartBorderColor = "0000CD";

            //Item details
            PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
            itemDetails.Name        = item_name;
            itemDetails.Amount      = new BasicAmountType(currencyCode_Type, roundeditmamt);
            itemDetails.Quantity    = Convert.ToInt32(item_quantity);
            itemDetails.Description = item_desc;
            itemDetails.Number      = item_id;

            //Add more items if necessary by using the class 'PaymentDetailsItemType'

            // Payment Information
            List <PaymentDetailsType> paymentDetailsList = new List <PaymentDetailsType>();

            PaymentDetailsType paymentDetails = new PaymentDetailsType();
            paymentDetails.PaymentAction = payment_ActionCode_Type;
            paymentDetails.ItemTotal     = new BasicAmountType(currencyCode_Type, roundeditmamt);//item amount
            //paymentDetails.TaxTotal = new BasicAmountType(currencyCode_Type, tax_amount); //tax amount;
            //paymentDetails.ShippingTotal = new BasicAmountType(currencyCode_Type, shipping_amount); //shipping amount
            //paymentDetails.HandlingTotal = new BasicAmountType(currencyCode_Type, handling_amount); //handling amount
            //paymentDetails.ShippingDiscount = new BasicAmountType(currencyCode_Type, shipping_discount_amount); //shipping discount
            //paymentDetails.InsuranceTotal = new BasicAmountType(currencyCode_Type, insurance_amount); //insurance amount
            paymentDetails.OrderTotal = new BasicAmountType(currencyCode_Type, roundedtotal); // order total amount

            paymentDetails.PaymentDetailsItem.Add(itemDetails);

            // Unique identifier for the merchant.
            SellerDetailsType sellerDetails = new SellerDetailsType();
            sellerDetails.PayPalAccountID = SellerEmail;
            paymentDetails.SellerDetails  = sellerDetails;

            if (ecMethod != null && ecMethod == "MarkExpressCheckout")
            {
                paymentDetails.ShipToAddress = shipToAddress;
            }
            paymentDetailsList.Add(paymentDetails);
            setExpressCheckoutRequestDetails.PaymentDetails = paymentDetailsList;

            // Collect Shipping details if MARK express checkout

            SetExpressCheckoutReq         setExpressCheckout        = new SetExpressCheckoutReq();
            SetExpressCheckoutRequestType setExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails);
            setExpressCheckout.SetExpressCheckoutRequest = setExpressCheckoutRequest;

            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

            // API call
            // Invoke the SetExpressCheckout method in service wrapper object
            responseSetExpressCheckoutResponseType = service.SetExpressCheckout(setExpressCheckout);

            if (responseSetExpressCheckoutResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "SetExpressCheckout API Operation - ";
                acknowledgement += responseSetExpressCheckoutResponseType.Ack.ToString();
                //logger.Debug(acknowledgement + "\n");
                System.Diagnostics.Debug.WriteLine(acknowledgement + "\n");
                // # Success values
                if (responseSetExpressCheckoutResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // # Redirecting to PayPal for authorization
                    // Once you get the "Success" response, needs to authorise the
                    // transaction by making buyer to login into PayPal. For that,
                    // need to construct redirect url using EC token from response.
                    // Express Checkout Token
                    string EcToken = responseSetExpressCheckoutResponseType.Token;
                    //logger.Info("Express Checkout Token : " + EcToken + "\n");
                    System.Diagnostics.Debug.WriteLine("Express Checkout Token : " + EcToken + "\n");
                    // Store the express checkout token in session to be used in GetExpressCheckoutDetails & DoExpressCheckout API operations
                    Session["EcToken"] = EcToken;
                    Response.Redirect(RedirectUrl + HttpUtility.UrlEncode(EcToken), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseSetExpressCheckoutResponseType.Errors;
                    string           errorMessage  = "";
                    foreach (ErrorType error in errorMessages)
                    {
                        //logger.Debug("API Error Message : " + error.LongMessage);
                        System.Diagnostics.Debug.WriteLine("API Error Message : " + error.LongMessage + "\n");
                        errorMessage = errorMessage + error.LongMessage;
                    }
                    //Redirect to error page in case of any API errors
                    CurrContext.Items.Add("APIErrorMessage", errorMessage);
                    Server.Transfer("~/Response.aspx");
                }
            }
        }
        catch (System.Exception ex)
        {
            // Log the exception message
            //logger.Debug("Error Message : " + ex.Message);
            System.Diagnostics.Debug.WriteLine("Error Message : " + ex.Message);
        }
    }
コード例 #15
0
ファイル: PaypalAPI.cs プロジェクト: mikeshane/MerchantTribe
        public SetExpressCheckoutResponseType SetExpressCheckout(string paymentAmount, string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, String name, String countryISOCode, String street1, String street2, String city, String region, String postalCode, String phone, string invoiceId)
        {
            // Create the request object
            SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();

            // Create the request details object
            pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            pp_request.SetExpressCheckoutRequestDetails.PaymentAction          = paymentAction;
            pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;

            pp_request.SetExpressCheckoutRequestDetails.AddressOverride = "1";
            pp_request.SetExpressCheckoutRequestDetails.InvoiceID       = invoiceId;

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value      = paymentAmount;

            pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
            pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;

            pp_request.SetExpressCheckoutRequestDetails.Address = new AddressType();
            pp_request.SetExpressCheckoutRequestDetails.Address.AddressStatusSpecified = false;
            pp_request.SetExpressCheckoutRequestDetails.Address.AddressOwnerSpecified  = false;

            pp_request.SetExpressCheckoutRequestDetails.Address.Street1          = street1;
            pp_request.SetExpressCheckoutRequestDetails.Address.Street2          = street2;
            pp_request.SetExpressCheckoutRequestDetails.Address.CityName         = city;
            pp_request.SetExpressCheckoutRequestDetails.Address.StateOrProvince  = region;
            pp_request.SetExpressCheckoutRequestDetails.Address.PostalCode       = postalCode;
            pp_request.SetExpressCheckoutRequestDetails.Address.CountrySpecified = true;
            pp_request.SetExpressCheckoutRequestDetails.Address.Country          = GetCountryCode(countryISOCode);
            pp_request.SetExpressCheckoutRequestDetails.Address.Phone            = phone;
            pp_request.SetExpressCheckoutRequestDetails.Address.Name             = name;
            return((SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request));
        }
コード例 #16
0
 private PaymentDetailsType GetPaypalPaymentDetail(CurrencyCodeType currency, PaymentActionCodeType paymentAction)
 {
     var paymentDetails = new PaymentDetailsType { PaymentAction = paymentAction };
     var itemTotal = Ch.Cart.Subtotal - Ch.Cart.LineItemDiscountTotal - Ch.Cart.FormDiscountTotal;
     paymentDetails.PaymentDetailsItem.AddRange(GetPaypalPaymentDetailsItemTypes(currency));
     paymentDetails.ItemTotal = new BasicAmountType(currency, FormatMoney(itemTotal));
     paymentDetails.ShippingTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.ShippingTotal));
     paymentDetails.HandlingTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.HandlingTotal));
     paymentDetails.TaxTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.TaxTotal));
     paymentDetails.OrderTotal = new BasicAmountType(currency, FormatMoney(Ch.Cart.Total));
     paymentDetails.ShippingDiscount = new BasicAmountType(currency, FormatMoney(-Ch.Cart.ShipmentDiscountTotal));
     
     return paymentDetails;
 }
コード例 #17
0
ファイル: PaypalAPI.cs プロジェクト: mikeshane/MerchantTribe
        public DoExpressCheckoutPaymentResponseType DoExpressCheckoutPayment(string token, string payerID, string paymentAmount, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, string invoiceId)
        {
            // Create the request object
            DoExpressCheckoutPaymentRequestType pp_request = new DoExpressCheckoutPaymentRequestType();

            // Create the request details object
            pp_request.DoExpressCheckoutPaymentRequestDetails               = new DoExpressCheckoutPaymentRequestDetailsType();
            pp_request.DoExpressCheckoutPaymentRequestDetails.Token         = token;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PayerID       = payerID;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentAction = paymentAction;


            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails            = new PaymentDetailsType();
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.InvoiceID  = invoiceId;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();

            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.OrderTotal.Value      = paymentAmount;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.ButtonSource          = "BVCommerce_Cart_EC_US";
            return((DoExpressCheckoutPaymentResponseType)caller.Call("DoExpressCheckoutPayment", pp_request));
        }
コード例 #18
0
ファイル: PaypalAPI.cs プロジェクト: wncoder/core
        public DoDirectPaymentResponseType DoDirectPayment(string paymentAmount, string buyerBillingLastName,
                                                           string buyerBillingFirstName,
                                                           string buyerShippingLastName, string buyerShippingFirstName, string buyerBillingAddress1,
                                                           string buyerBillingAddress2,
                                                           string buyerBillingCity, string buyerBillingState, string buyerBillingPostalCode,
                                                           CountryCodeType buyerBillingCountryCode,
                                                           string creditCardType, string creditCardNumber, string CVV2, int expMonth, int expYear,
                                                           PaymentActionCodeType paymentAction,
                                                           string ipAddress, string buyerShippingAddress1, string buyerShippingAddress2, string buyerShippingCity,
                                                           string buyerShippingState,
                                                           string buyerShippingPostalCode, CountryCodeType buyerShippingCountryCode, string invoiceId,
                                                           CurrencyCodeType storeCurrency)
        {
            // Create the request object
            var pp_Request = new DoDirectPaymentRequestType
            {
                DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType
                {
                    IPAddress         = ipAddress,
                    MerchantSessionId = string.Empty,
                    PaymentAction     = paymentAction,
                    CreditCard        = new CreditCardDetailsType
                    {
                        CreditCardNumber = creditCardNumber
                    }
                }
            };

            // Create the request details object

            switch (creditCardType)
            {
            case "Visa":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa;
                break;

            case "MasterCard":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard;
                break;

            case "Discover":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Discover;
                break;

            case "Amex":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Amex;
                break;
            }

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CVV2              = CVV2;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonth          = expMonth;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYear           = expYear;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonthSpecified = true;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYearSpecified  = true;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType
            {
                Payer        = string.Empty,
                PayerID      = string.Empty,
                PayerStatus  = PayPalUserStatusCodeType.unverified,
                PayerCountry = CountryCodeType.US,
                Address      = new AddressType
                {
                    Street1          = buyerBillingAddress1,
                    Street2          = buyerBillingAddress2,
                    CityName         = buyerBillingCity,
                    StateOrProvince  = buyerBillingState,
                    PostalCode       = buyerBillingPostalCode,
                    Country          = buyerBillingCountryCode,
                    CountrySpecified = true
                }
            };

            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType
            {
                ShipToAddress = new AddressType
                {
                    Name = buyerShippingFirstName + " " +
                           buyerShippingLastName,
                    Street1          = buyerShippingAddress1,
                    Street2          = buyerShippingAddress2,
                    CityName         = buyerShippingCity,
                    StateOrProvince  = buyerShippingState,
                    PostalCode       = buyerShippingPostalCode,
                    Country          = buyerShippingCountryCode,
                    CountrySpecified = true
                }
            };

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType
            {
                FirstName = buyerBillingFirstName,
                LastName  = buyerBillingLastName
            };

            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.InvoiceID  = invoiceId;

            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = storeCurrency;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value      = paymentAmount;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ButtonSource          = "HotcakesCommerce_Cart_DP_US";

            return((DoDirectPaymentResponseType)caller.Call("DoDirectPayment", pp_Request));
        }
コード例 #19
0
ファイル: PaypalAPI.cs プロジェクト: appliedi/MerchantTribe
        public SetExpressCheckoutResponseType SetExpressCheckout(string paymentAmount, string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, string invoiceId)
        {
            // Create the request object
            SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();

            // Create the request details object
            pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
            pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;
            pp_request.SetExpressCheckoutRequestDetails.InvoiceID = invoiceId;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();

            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;            

            pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
            pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;

            return (SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request);
        }
コード例 #20
0
ファイル: PaypalAPI.cs プロジェクト: wncoder/core
        public SetExpressCheckoutResponseType SetExpressCheckout(PaymentDetailsItemType[] itemsDetails,
                                                                 string itemsTotal, string taxTotal, string orderTotal,
                                                                 string returnURL, string cancelURL, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType,
                                                                 SolutionTypeType solutionType, string invoiceId, bool isNonShipping)
        {
            // Create the request object
            var pp_request = new SetExpressCheckoutRequestType
            {
                // Create the request details object
                SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType
                {
                    CancelURL             = cancelURL,
                    ReturnURL             = returnURL,
                    NoShipping            = isNonShipping ? "1" : "0",
                    SolutionType          = solutionType,
                    SolutionTypeSpecified = true
                }
            };

            //pp_request.SetExpressCheckoutRequestDetails.ReqBillingAddress = (isNonShipping ? "1" : "0");

            var paymentDetails = new PaymentDetailsType
            {
                InvoiceID              = invoiceId,
                PaymentAction          = paymentAction,
                PaymentActionSpecified = true,
                PaymentDetailsItem     = itemsDetails,
                ItemTotal              = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = itemsTotal
                },
                TaxTotal = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = taxTotal
                },
                OrderTotal = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = orderTotal
                }
            };

            pp_request.SetExpressCheckoutRequestDetails.PaymentDetails = new[] { paymentDetails };

            return((SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request));
        }
コード例 #21
0
ファイル: PaypalAPI.cs プロジェクト: appliedi/MerchantTribe
        public DoExpressCheckoutPaymentResponseType DoExpressCheckoutPayment(string token, string payerID, string paymentAmount, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType, string invoiceId)
        {
            // Create the request object
            DoExpressCheckoutPaymentRequestType pp_request = new DoExpressCheckoutPaymentRequestType();

            // Create the request details object
            pp_request.DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
            pp_request.DoExpressCheckoutPaymentRequestDetails.Token = token;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PayerID = payerID;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentAction = paymentAction;
            

            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.InvoiceID = invoiceId;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();

            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = currencyCodeType;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.OrderTotal.Value = paymentAmount;
            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails.ButtonSource = "BVCommerce_Cart_EC_US";
            return (DoExpressCheckoutPaymentResponseType)caller.Call("DoExpressCheckoutPayment", pp_request);
        }
コード例 #22
0
ファイル: PaypalAPI.cs プロジェクト: wncoder/core
        public SetExpressCheckoutResponseType SetExpressCheckout(PaymentDetailsItemType[] itemsDetails,
                                                                 string itemsTotal, string taxTotal, string shippingTotal,
                                                                 string orderTotal, string returnURL, string cancelURL, PaymentActionCodeType paymentAction,
                                                                 CurrencyCodeType currencyCodeType, SolutionTypeType solutionType, string name,
                                                                 string countryISOCode, string street1, string street2, string city, string region, string postalCode,
                                                                 string phone, string invoiceId, bool isNonShipping)
        {
            // Create the request object
            var pp_request = new SetExpressCheckoutRequestType
            {
                SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType
                {
                    CancelURL             = cancelURL,
                    ReturnURL             = returnURL,
                    AddressOverride       = "1",
                    NoShipping            = isNonShipping ? "1" : "0",
                    SolutionType          = solutionType,
                    SolutionTypeSpecified = true
                }
            };

            // Create the request details object

            //pp_request.SetExpressCheckoutRequestDetails.ReqBillingAddress = (isNonShipping ? "1" : "0");

            var paymentDetails = new PaymentDetailsType
            {
                InvoiceID              = invoiceId,
                PaymentAction          = paymentAction,
                PaymentActionSpecified = true,
                PaymentDetailsItem     = itemsDetails,
                ItemTotal              = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = itemsTotal
                },
                TaxTotal = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = taxTotal
                },
                ShippingTotal = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = shippingTotal
                },
                OrderTotal = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = orderTotal
                },
                ShipToAddress = new AddressType
                {
                    AddressStatusSpecified = false,
                    AddressOwnerSpecified  = false,
                    Street1          = street1,
                    Street2          = street2,
                    CityName         = city,
                    StateOrProvince  = region,
                    PostalCode       = postalCode,
                    CountrySpecified = true,
                    Country          = GetCountryCode(countryISOCode),
                    Phone            = phone,
                    Name             = name
                }
            };

            pp_request.SetExpressCheckoutRequestDetails.PaymentDetails = new[] { paymentDetails };

            return((SetExpressCheckoutResponseType)caller.Call("SetExpressCheckout", pp_request));
        }
コード例 #23
0
		private PaymentDetailsType GetPaypalPaymentDetail(CurrencyCodeType currency, PaymentActionCodeType paymentAction, PaymentIn payment)
		{
			var paymentDetails = new PaymentDetailsType { PaymentAction = paymentAction };
			paymentDetails.OrderTotal = new BasicAmountType(currency, FormatMoney(payment.Sum));

			return paymentDetails;
		}
コード例 #24
0
ファイル: PaypalAPI.cs プロジェクト: wncoder/core
        public DoExpressCheckoutPaymentResponseType DoExpressCheckoutPayment(string token, string payerID,
                                                                             string paymentAmount, PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType,
                                                                             string invoiceId)
        {
            // Create the request object
            var pp_request = new DoExpressCheckoutPaymentRequestType
            {
                DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType
                {
                    Token   = token,
                    PayerID = payerID
                }
            };

            // Create the request details object

            var paymentDetails = new PaymentDetailsType
            {
                InvoiceID              = invoiceId,
                PaymentAction          = paymentAction,
                PaymentActionSpecified = true,
                OrderTotal             = new BasicAmountType
                {
                    currencyID = currencyCodeType,
                    Value      = paymentAmount
                }
            };

            paymentDetails.ButtonSource = "HotcakesCommerce_Cart_EC_US";

            pp_request.DoExpressCheckoutPaymentRequestDetails.PaymentDetails = new[] { paymentDetails };
            return((DoExpressCheckoutPaymentResponseType)caller.Call("DoExpressCheckoutPayment", pp_request));
        }
コード例 #25
0
        public override bool ProcessCheckout(OrderTaskContext context)
        {
            if (context.HccApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                try
                {
                    PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(context.HccApp.CurrentStore);

                    string cartReturnUrl = HccUrlBuilder.RouteHccUrl(HccRoute.ThirdPartyPayment, null, Uri.UriSchemeHttps);
                    string cartCancelUrl = HccUrlBuilder.RouteHccUrl(HccRoute.Checkout, null, Uri.UriSchemeHttps);

                    EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
                    EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

                    PaymentActionCodeType mode = PaymentActionCodeType.Authorization;
                    if (!context.HccApp.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    // Accelerated boarding
                    if (string.IsNullOrWhiteSpace(context.HccApp.CurrentStore.Settings.PayPal.UserName))
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    var  solutionType  = context.HccApp.CurrentStore.Settings.PayPal.RequirePayPalAccount ? SolutionTypeType.Mark : SolutionTypeType.Sole;
                    bool isNonShipping = !context.Order.HasShippingItems;

                    bool addressSupplied = false;
                    if (context.Inputs["ViaCheckout"] != null &&
                        context.Inputs["ViaCheckout"].Value == "1")
                    {
                        addressSupplied = true;
                        context.Order.CustomProperties.Add("hcc", "ViaCheckout", "1");
                    }

                    PaymentDetailsItemType[] itemsDetails = GetOrderItemsDetails(context);

                    SetExpressCheckoutResponseType expressResponse;
                    if (addressSupplied)
                    {
                        Contacts.Address address = context.Order.ShippingAddress;

                        // in some cases, this logic will be hit with non-shipping orders, causing an exception
                        if (address == null || string.IsNullOrEmpty(address.Bvin))
                        {
                            // this is a workaround for that use case
                            address = context.Order.BillingAddress;
                        }

                        if (address.CountryData != null)
                        {
                            var itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;
                            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                            {
                                itemsTotalWithoutTax -= context.Order.ItemsTax;
                            }
                            string itemsTotal = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
                            string taxTotal   = context.Order.TotalTax.ToString("N", CultureInfo.InvariantCulture);
                            var    shippingTotalWithoutTax = context.Order.TotalShippingAfterDiscounts;
                            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                            {
                                shippingTotalWithoutTax -= context.Order.ShippingTax;
                            }
                            string shippingTotal = shippingTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);

                            string orderTotal = context.Order.TotalGrand.ToString("N", CultureInfo.InvariantCulture);
                            expressResponse = ppAPI.SetExpressCheckout(
                                itemsDetails,
                                itemsTotal,
                                taxTotal,
                                shippingTotal,
                                orderTotal,
                                cartReturnUrl,
                                cartCancelUrl,
                                mode,
                                PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency),
                                solutionType,
                                address.FirstName + " " + address.LastName,
                                address.CountryData.IsoCode,
                                address.Line1,
                                address.Line2,
                                address.City,
                                address.RegionBvin,
                                address.PostalCode,
                                address.Phone,
                                context.Order.OrderNumber + Guid.NewGuid().ToString(),
                                isNonShipping);
                            if (expressResponse == null)
                            {
                                EventLog.LogEvent("PayPal Express Checkout", "Express Response Was Null!", EventLogSeverity.Error);
                            }
                        }
                        else
                        {
                            EventLog.LogEvent("StartPaypalExpressCheckout", "Country with bvin " + address.CountryBvin + " was not found.", EventLogSeverity.Error);
                            return(false);
                        }
                    }
                    else
                    {
                        decimal includedTax = 0;
                        if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                        {
                            includedTax = context.Order.ItemsTax;
                        }
                        string taxTotal             = includedTax.ToString("N", CultureInfo.InvariantCulture);
                        var    itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;
                        if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                        {
                            itemsTotalWithoutTax -= context.Order.ItemsTax;
                        }
                        string itemsTotal = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
                        string orderTotal = context.Order.TotalOrderAfterDiscounts.ToString("N", CultureInfo.InvariantCulture);
                        expressResponse = ppAPI.SetExpressCheckout(itemsDetails,
                                                                   itemsTotal,
                                                                   taxTotal,
                                                                   orderTotal,
                                                                   cartReturnUrl,
                                                                   cartCancelUrl,
                                                                   mode,
                                                                   PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency),
                                                                   solutionType,
                                                                   context.Order.OrderNumber + Guid.NewGuid().ToString(),
                                                                   isNonShipping);
                        if (expressResponse == null)
                        {
                            EventLog.LogEvent("PayPal Express Checkout", "Express Response2 Was Null!", EventLogSeverity.Error);
                        }
                    }

                    if (expressResponse.Ack == AckCodeType.Success || expressResponse.Ack == AckCodeType.SuccessWithWarning)
                    {
                        context.Order.ThirdPartyOrderId = expressResponse.Token;

                        // Recording of this info is handled on the paypal express
                        // checkout page instead of here.
                        //Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order);
                        //payManager.PayPalExpressAddInfo(context.Order.TotalGrand, expressResponse.Token);

                        EventLog.LogEvent("PayPal Express Checkout", "Response SUCCESS", EventLogSeverity.Information);

                        Orders.OrderNote note = new Orders.OrderNote();
                        note.IsPublic = false;
                        note.Note     = "Paypal Order Accepted With Paypal Order Number: " + expressResponse.Token;
                        context.Order.Notes.Add(note);
                        if (context.HccApp.OrderServices.Orders.Update(context.Order))
                        {
                            string urlTemplate;
                            if (string.Compare(context.HccApp.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
                            {
                                urlTemplate = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}";
                            }
                            else
                            {
                                urlTemplate = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}";
                            }
                            HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);
                            httpContext.Response.Redirect(string.Format(urlTemplate, expressResponse.Token), true);
                        }
                        return(true);
                    }
                    else
                    {
                        foreach (ErrorType ppError in expressResponse.Errors)
                        {
                            context.Errors.Add(new WorkflowMessage(ppError.ErrorCode, ppError.ShortMessage, true));

                            //create a note to save the paypal error info onto the order
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "Paypal error number: " + ppError.ErrorCode + " Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage;
                            context.Order.Notes.Add(note);

                            EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to SetExpressCheckout: Total=" + string.Format("{0:c}", context.Order.TotalOrderBeforeDiscounts) + " Cart Return Url: " + cartReturnUrl + " Cart Cancel Url: " + cartCancelUrl, EventLogSeverity.Error);
                        }
                        context.Errors.Add(new WorkflowMessage("Paypal checkout error", GlobalLocalization.GetString("PaypalCheckoutCustomerError"), true));
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    EventLog.LogEvent("Paypal Express Checkout", "Exception occurred during call to Paypal: " + ex.ToString(), EventLogSeverity.Error);
                    context.Errors.Add(new WorkflowMessage("Paypal checkout error", GlobalLocalization.GetString("PaypalCheckoutCustomerError"), true));
                    return(false);
                }
            }

            return(false);
        }
コード例 #26
0
ファイル: PaypalAPI.cs プロジェクト: mikeshane/MerchantTribe
        public DoDirectPaymentResponseType DoDirectPayment(string paymentAmount, string buyerBillingLastName, string buyerBillingFirstName, string buyerShippingLastName, string buyerShippingFirstName, string buyerBillingAddress1, string buyerBillingAddress2, string buyerBillingCity, string buyerBillingState, string buyerBillingPostalCode, CountryCodeType buyerBillingCountryCode, string creditCardType, string creditCardNumber, string CVV2, int expMonth, int expYear, PaymentActionCodeType paymentAction, string ipAddress, string buyerShippingAddress1, string buyerShippingAddress2, string buyerShippingCity, string buyerShippingState, string buyerShippingPostalCode, CountryCodeType buyerShippingCountryCode, string invoiceId)
        {
            // Create the request object
            DoDirectPaymentRequestType pp_Request = new DoDirectPaymentRequestType();

            // Create the request details object
            pp_Request.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();

            pp_Request.DoDirectPaymentRequestDetails.IPAddress                   = ipAddress;
            pp_Request.DoDirectPaymentRequestDetails.MerchantSessionId           = "";
            pp_Request.DoDirectPaymentRequestDetails.PaymentAction               = paymentAction;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard                  = new CreditCardDetailsType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = creditCardNumber;
            switch (creditCardType)
            {
            case "Visa":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Visa;
                break;

            case "MasterCard":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.MasterCard;
                break;

            case "Discover":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Discover;
                break;

            case "Amex":
                pp_Request.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = CreditCardTypeType.Amex;
                break;
            }
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CVV2              = CVV2;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonth          = expMonth;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYear           = expYear;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpMonthSpecified = true;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.ExpYearSpecified  = true;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner              = new PayerInfoType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Payer        = "";
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerID      = "";
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerStatus  = PayPalUserStatusCodeType.unverified;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerCountry = CountryCodeType.US;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address                  = new AddressType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1          = buyerBillingAddress1;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2          = buyerBillingAddress2;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName         = buyerBillingCity;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince  = buyerBillingState;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode       = buyerBillingPostalCode;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country          = buyerBillingCountryCode;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;

            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress                  = new AddressType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name             = buyerShippingFirstName + " " + buyerShippingLastName;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1          = buyerShippingAddress1;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street2          = buyerShippingAddress2;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName         = buyerShippingCity;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince  = buyerShippingState;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode       = buyerShippingPostalCode;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country          = buyerShippingCountryCode;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true;

            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName           = new PersonNameType();
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = buyerBillingFirstName;
            pp_Request.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName  = buyerBillingLastName;

            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.InvoiceID  = invoiceId;

            // NOTE: The only currency supported by the Direct Payment API at this time is US dollars (USD).
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value      = paymentAmount;
            pp_Request.DoDirectPaymentRequestDetails.PaymentDetails.ButtonSource          = "BVCommerce_Cart_DP_US";
            return((DoDirectPaymentResponseType)caller.Call("DoDirectPayment", pp_Request));
        }
 /// <summary>
 /// Constructor with arguments
 /// </summary>
 public DoReferenceTransactionRequestDetailsType(string referenceID, PaymentActionCodeType? paymentAction, PaymentDetailsType paymentDetails)
 {
     this.ReferenceID = referenceID;
     this.PaymentAction = paymentAction;
     this.PaymentDetails = paymentDetails;
 }
コード例 #28
0
        protected DoExpressCheckoutPaymentResponseType ECDoExpressCheckoutCode(string token, string payerID, string paymentAmount,
            PaymentActionCodeType paymentAction, CurrencyCodeType currencyCodeType)
        {
            var caller = CreateCaller();

            var pp_request = new DoExpressCheckoutPaymentRequestType
            {
                Version = "51.0",
                DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType
                {
                    Token = token,
                    PayerID = payerID,
                    PaymentAction = paymentAction,
                    PaymentDetails = new PaymentDetailsType
                    {
                        OrderTotal = new BasicAmountType
                        {
                            currencyID = currencyCodeType,
                            Value = paymentAmount
                        }
                    }
                }
            };

            return (DoExpressCheckoutPaymentResponseType)caller.Call("DoExpressCheckoutPayment", pp_request);
        }