コード例 #1
0
    protected void ibCompletePaypalOrder_Click(object sender, ImageClickEventArgs e)
    {
        Product[] products = new Product[gvShoppingCart.Rows.Count];
        foreach (GridViewRow row in gvShoppingCart.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                Product prod = new Product();

                DataKey data = gvShoppingCart.DataKeys[row.DataItemIndex];

                prod.ProductId = int.Parse(data.Values["ProductId"].ToString());

                Literal litProductName = (Literal)row.FindControl("litProductName");
                prod.Name = litProductName.Text;

                Literal litQuantity = (Literal)row.FindControl("litQuantity");
                prod.Quantity = int.Parse(litQuantity.Text);

                Literal litUnitPrice = (Literal)row.FindControl("litUnitPrice");
                litUnitPrice.Text = litUnitPrice.Text.Replace("£", "");
                prod.Price = Convert.ToDecimal(litUnitPrice.Text);

                products.SetValue(prod, row.DataItemIndex);
            }
        }

        CurrentOrder.OrderDetails.Products = products;

        //order total
        this.litTotal.Text = this.litTotal.Text.Replace("£", "");
        this.CurrentOrder.OrderTotal = Convert.ToDecimal(this.litTotal.Text);
        this.CurrentOrder.EndUserId = this.CurrentEndUser.EndUserId;

        string token = Request.QueryString["token"];
        string payerId = Request.QueryString["PayerID"];

        //DoExpressCheckoutPayment
        PayPalManager payPal = new PayPalManager();
        PayPalInformation payPalInformation = new PayPalInformation();
        payPalInformation.Order = this.CurrentOrder;
        payPalInformation.Order.PayerId = payerId;
        payPalInformation.Order.SubTotal = this.CurrentOrder.OrderTotal;

        // #HACK: WJ: sub null for items array below to get it working
        PayPalManager.OrderInfo ppOrderInfo = new PayPalManager.OrderInfo();

        //this call returns an order info object
        //double orderTotal = Convert.ToDouble(this.CommercePage.Basket.GetBaseTotalAfterDiscount());

        double orderTotal = Math.Round(Convert.ToDouble(base.CurrentOrder.SubTotal), 2);

        // this call actually processes the payment
        ppOrderInfo = payPal.DoExpressCheckout(token, payPalInformation);

        string ack = ppOrderInfo.Ack; // says "Success" or "ERROR:..."
        string transactionId = ppOrderInfo.TransactionID;
        string receiptId = ppOrderInfo.ReceiptID;
        this.CurrentOrder.TransactionId = transactionId;
        // handle Paypal web service response
        if (ack.IndexOf("ERROR") != -1)
        {
            //find error placeholder, show and add error message
            ContentPlaceHolder cph = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");

            this.pnlOrderDeclined.Visible = true;

            this.lblTransactionFailureMessage.Text = ack;

            // also need to show a credit card payment option - to do.
        }
        else
        {
            // Transaction successful: complete order!
            ProcessAddOrder addOrder = new ProcessAddOrder();
            addOrder.Orders = this.CurrentOrder;

            try
            {
                addOrder.Invoke();
            }
            catch (Exception ex)
            {
                Response.Redirect("ErrorPage.aspx");
            }

            this.UpdateStockLevel();
            this.DeleteShoppingCart();

            // now forward to order completed page
            Response.Redirect("~/CheckOut/CheckOutReceipt.aspx?ec=true");
        }
    }
コード例 #2
0
    //Get PayPal Token and redirect to pay pal
    protected void ibGetPaypalToken_Click(object sender, ImageClickEventArgs e)
    {
        //set the Order object
        if (this.LiveFreeRangePage.IsValid)
        {
            //this.LiveFreeRangePage.CurrentEndUser.FirstName = this.txtFirstName.Text;
            //this.LiveFreeRangePage.CurrentEndUser.LastName = this.txtLastName.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.AddressLine = this.txtAddress.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.AddressLine2 = this.txtAddress2.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.City = this.txtCity.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.PostalCode = this.txtPostalCode.Text;

            //this.LiveFreeRangePage.CurrentOrder = new Orders();
            //this.LiveFreeRangePage.CurrentOrder.Enduser.FirstName = this.txtFirstName.Text;
            //this.LiveFreeRangePage.CurrentOrder.Enduser.LastName = this.txtLastName.Text;

            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.AddressLine = this.txtAddress.Text;
            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.AddressLine2 = this.txtAddress2.Text;
            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.City = this.txtCity.Text;
            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.PostalCode = this.txtPostalCode.Text;

            //this.LiveFreeRangePage.CurrentOrder.CreditCard.CardType = this.ddlCreditCardType.SelectedItem.Value;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Number = this.txtCreditCardNumber.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.SecurityCode = this.txtSecurityCode.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.ExpMonth = int.Parse(this.ddlExpMonth.SelectedItem.Text);
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.ExpYear = int.Parse(this.ddlExpYear.SelectedItem.Text);

            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.AddressLine = this.txtBillingAddress.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.AddressLine2 = this.txtBillingAddress2.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.City = this.txtBillingCity.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.PostalCode = this.txtBillingPostalCode.Text;

            this.LiveFreeRangePage.CurrentOrder = new Orders();
            this.litTax.Text = this.litTax.Text.Replace("£", "");
            this.LiveFreeRangePage.CurrentOrder.Tax = Convert.ToDecimal(litTax.Text);

            this.litSubTotal.Text = this.litSubTotal.Text.Replace("£", "");
            this.LiveFreeRangePage.CurrentOrder.SubTotal = Convert.ToDecimal(this.litSubTotal.Text);

            this.LiveFreeRangePage.CurrentOrder.ShippingTotal = Convert.ToDecimal(ddlShippingOption.SelectedItem.Value);

            //add order object to paypal information object
            PayPalManager payPal = new PayPalManager();
            PayPalInformation payPalInformation = new PayPalInformation();
            payPalInformation.Order = this.LiveFreeRangePage.CurrentOrder;

            //set required url's
            string payPalSubmitUrl = string.Empty;

            if (!(PayPalManager.IsPaypalSandboxOn()))
                payPalSubmitUrl = "https://www.livefreerange.com";
            else
                payPalSubmitUrl = "http://localhost/Web/CheckOut/CheckOut.aspx";

            string payPalCancelUrl = payPalSubmitUrl;

            //pass paypal information to setexpresscheckout and return a token.
            string payPalToken = payPal.SetExpressCheckout(payPalInformation, payPalSubmitUrl, payPalCancelUrl);

            //redirect to paypal with token
            if (payPalToken.ToLower().IndexOf("error") == -1)
                Response.Redirect(PayPalManager.GetPaypalFormSubmissionUrl()
                    + "?cmd=_express-checkout&token="
                    + payPalToken);
            else
            {
                //find error placeholder, show and add error message
                Panel pnlOrderDeclined = (Panel)Page.FindControl("pnlOrderDeclined");
                pnlOrderDeclined.Visible = true;

                Label lblTransactionFailureMessage = (Label)Page.FindControl("lblTransactionFailureMessage");
                lblTransactionFailureMessage.Text = payPalToken;
            }
        }
    }
コード例 #3
0
    //Complete Pay Pal Order
    protected void ibCompletePaypalOrder_Click(object sender, ImageClickEventArgs e)
    {
        //GetExpressCheckoutDetails - required if shipping goods or if we need the billing address

        /*
        APIWrapper ppGetDetails = new APIWrapper();
        APIWrapper.PayerInfo ppInfo = new APIWrapper.PayerInfo();
        ppInfo = ppGetDetails.GetExpressCheckout(
        */

        string token = Request.QueryString["token"];
        string payerId = Request.QueryString["PayerID"];

        //DoExpressCheckoutPayment
        PayPalManager payPal = new PayPalManager();
        PayPalInformation payPalInformation = new PayPalInformation();
        payPalInformation.Order = this.LiveFreeRangePage.CurrentOrder;

        // #HACK: WJ: sub null for items array below to get it working
        PayPalManager.OrderInfo ppOrderInfo = new PayPalManager.OrderInfo();

        //this call returns an order info object
        //double orderTotal = Convert.ToDouble(this.CommercePage.Basket.GetBaseTotalAfterDiscount());

        this.LiveFreeRangePage.CurrentOrder = new Orders();
        double orderTotal = Convert.ToDouble(this.LiveFreeRangePage.CurrentOrder.SubTotal);

        // this call actually processes the payment
        ppOrderInfo =  payPal.DoExpressCheckout(token, payPalInformation);

        string ack = ppOrderInfo.Ack; // says "Success" or "ERROR:..."
        string transactionId = ppOrderInfo.TransactionID;
        string receiptId = ppOrderInfo.ReceiptID;

        // handle Paypal web service response
        if (ack.IndexOf("ERROR") != -1)
        {
            //find error placeholder, show and add error message
            ContentPlaceHolder cph = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");

            Panel pnlOrderDeclined = (Panel)cph.FindControl("pnlOrderDeclined");
            pnlOrderDeclined.Visible = true;

            Label lblTransactionFailureMessage = (Label)cph.FindControl("lblTransactionFailureMessage");
            lblTransactionFailureMessage.Text = ack;

            // also need to show a credit card payment option - to do.
        }
        else
        {
            // Transaction successful: complete order!
            ProcessAddOrder addOrder = new ProcessAddOrder();
            addOrder.Orders = this.LiveFreeRangePage.CurrentOrder;

            try
            {
                addOrder.Invoke();
            }
            catch (Exception ex)
            {
                Response.Redirect("ErrorPage.aspx");
            }

            this.UpdateStockLevel();
            this.DeleteShoppingCart();

            // now forward to order completed page
            Response.Redirect("~/Web/CheckOutReceipt.aspx");
        }
    }
コード例 #4
0
    //Get PayPal Token and redirect to pay pal
    protected void ibGetPaypalToken_Click(object sender, ImageClickEventArgs e)
    {
        //set the Order object
        if (this.IsValid)
        {
            this.CurrentOrder = new Orders();
            this.litTax.Text = this.litTax.Text.Replace("£", "");
            this.CurrentOrder.Tax = Math.Round(Convert.ToDecimal(litTax.Text),2);

            this.litSubTotal.Text = this.litSubTotal.Text.Replace("£", "");
            this.CurrentOrder.SubTotal = Math.Round(Convert.ToDecimal(this.litSubTotal.Text),2);

            this.CurrentOrder.ShippingTotal = Math.Round(Convert.ToDecimal(ddlShippingOption.SelectedItem.Value));

            //add order object to paypal information object
            PayPalManager payPal = new PayPalManager();
            PayPalInformation payPalInformation = new PayPalInformation();
            payPalInformation.Order = this.CurrentOrder;

            //set required url's
            string payPalSubmitUrl = string.Empty;

            if (!(PayPalManager.IsPaypalSandboxOn()))
                payPalSubmitUrl = "https://www.livefreerange.com";
            else
                payPalSubmitUrl = "http://localhost/Web/CheckOut/CheckOut.aspx";

            string payPalCancelUrl = payPalSubmitUrl;

            //pass paypal information to setexpresscheckout and return a token.
            string payPalToken = payPal.SetExpressCheckout(payPalInformation, payPalSubmitUrl, payPalCancelUrl);

            //redirect to paypal with token
            if (payPalToken.ToLower().IndexOf("error") == -1)
            {

                Response.Redirect(PayPalManager.GetPaypalFormSubmissionUrl() + "?cmd=_express-checkout&token=" + payPalToken);
            }
            //else
            //{
            //    //find error placeholder, show and add error message
            //    this.pnlOrderDeclined.Visible = true;
            //    this.lblTransactionFailureMessage.Text = payPalToken;
            //}

        }
    }
コード例 #5
0
    private void SubmitOrder()
    {
        PayPalManager payPal = new PayPalManager();
        PayPalInformation _payPalInformation = new PayPalInformation();

        _payPalInformation.Order = this.CurrentOrder;
        payPal.ProcessDirectPayment(_payPalInformation);

        //if payment successful - add Order to database and display
        if (payPal.IsSubmissionSuccess)
        {
            this.pnlSuccess.Visible = true;
            this.litOrderTotal.Text = string.Format("{0:c}", _payPalInformation.Order.OrderTotal);
            this.litTransactionId.Text = this.CurrentOrder.TransactionId;

            ProcessAddOrder addOrder = new ProcessAddOrder();
            addOrder.Orders = this.CurrentOrder;

            //when the order is added to the db must update stock level.
            //and also delete the corresponding baskets.

            try
            {
                addOrder.Invoke();
            }
            catch(Exception ex)
            {
                Response.Redirect("ErrorPage.aspx");
            }

            this.UpdateStockLevel();
            this.DeleteShoppingCart();
        }
        else
        {
            this.pnlFailure.Visible = true;
            this.litErrorMessage.Text = payPal.SubmissionError;
        }
    }
コード例 #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //if (!Request.IsSecureConnection)
     //{
     //    Response.Redirect(this.UrlBaseSSL);
     //}
       if (!IsPostBack)
     {
         token = Request.QueryString["token"];
         if (!string.IsNullOrEmpty(token))
         {
             payPalInformation = new PayPalInformation();
             payPalInformation.Order = this.CurrentOrder;
             payPal = new PayPalManager();
             payPalInformation = payPal.GetExpressCheckoutDetails(payPalInformation, token);
         }
         this.LoadShoppingCart();
         this.LoadInformation();
     }
 }
コード例 #7
0
        public string SetExpressCheckout(PayPalInformation payPalInformation, string payPalSubmitUrl, string payPalCancelUrl)
        {
            string result = string.Empty;

            SetExpressCheckoutRequestType SetECReqType = new SetExpressCheckoutRequestType();
            SetExpressCheckoutRequestDetailsType SetECReqTypeDetails = new SetExpressCheckoutRequestDetailsType();
            SetExpressCheckoutResponseType SetECRes = new SetExpressCheckoutResponseType();
            SetExpressCheckoutReq SetECReq = new SetExpressCheckoutReq();

            SetECReqType.Version = "53.0";
            SetECReqTypeDetails.OrderTotal = new BasicAmountType();
            SetECReqTypeDetails.OrderTotal.currencyID = CurrencyCodeType.GBP;

            SetECReqTypeDetails.OrderTotal.Value = payPalInformation.Order.SubTotal.ToString();

            //order.OrderTotal = GetAmountValue(payment.GrossAmount);
            //order.Tax = GetAmountValue(payment.TaxAmount);

            SetECReqTypeDetails.ReturnURL = ConfigurationManager.AppSettings["PayPalReturnURL"];
            SetECReqTypeDetails.CancelURL = ConfigurationManager.AppSettings["PayPalCancelURL"];

            SetECReqType.SetExpressCheckoutRequestDetails = SetECReqTypeDetails;
            SetECReq.SetExpressCheckoutRequest = SetECReqType;

            UserIdPasswordType user = new UserIdPasswordType();
            user.Username = this.APIUsername;
            user.Password = this.APIPassword;
            user.AuthCert = CertPath;
            PayPalAPIAASoapBinding ppInterface = new PayPalAPIAASoapBinding();
            ppInterface.Url = this.APIPath;
            ppInterface.RequesterCredentials = new CustomSecurityHeaderType();
            ppInterface.RequesterCredentials.Credentials = user;

            //this is .net 2.0 specific portion of the code
            //that allows us to have the .p12 on the filesystem and
            //not have to register it with WinHttpCertCfg uses
            //X509Certificate2 class.
            FileStream fStream = File.Open(CertPath, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[fStream.Length];

            int count = fStream.Read(buffer, 0, buffer.Length);

            fStream.Close();

            //use .net 2.0 X509Certificate2 class to read .p12 from filesystem
            //where "12345678" is the private key password
            X509Certificate2 x509 = new X509Certificate2(buffer, CertPassword);
            ppInterface.ClientCertificates.Add(x509);
            //service.ClientCertificates.Add(x509);

            try
            {
                SetECRes = ppInterface.SetExpressCheckout(SetECReq);
                switch (SetECRes.Ack)
                {
                    case AckCodeType.Success:
                        result = SetECRes.Token;
                        break;

                    default:  // show errors if Ack is NOT Success
                        result = "API response: <b>" + SetECRes.Ack.ToString() +
                            "</b><br> Timestamp: <b>" + SetECRes.Timestamp.ToLongTimeString() +
                            "</b><br> Version: <b>" + SetECRes.Version.ToString() +
                            "</b><br> Error code: <b>" + SetECRes.Errors[0].ErrorCode +
                            "</b><br> Short error: <b>" + SetECRes.Errors[0].ShortMessage +
                            "</b><br> Long error: <b>" + SetECRes.Errors[0].LongMessage;
                        break;
                }
            }
            catch (Exception ex)
            {
                result = ex.ToString();
            }

            return result;
        }
コード例 #8
0
        public void ProcessDirectPayment(PayPalInformation payPalInformation)
        {
            DoDirectPaymentRequestType DoDirectPmtReqType = new DoDirectPaymentRequestType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();

            //set payment action
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.IPAddress = HttpContext.Current.Request.UserHostAddress;

            #region set credit card info
            //set credit card info
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = payPalInformation.Order.CreditCard.Number;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = (CreditCardTypeType)StringToEnum(typeof(CreditCardTypeType), payPalInformation.Order.CreditCard.CardType);
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardTypeSpecified = true;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CVV2 = payPalInformation.Order.CreditCard.SecurityCode;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = payPalInformation.Order.CreditCard.ExpMonth;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpYear = payPalInformation.Order.CreditCard.ExpYear;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpMonthSpecified = true;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpYearSpecified = true;
            #endregion

            #region set billing address
            //set the billing address
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = payPalInformation.Order.Enduser.FirstName;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = payPalInformation.Order.Enduser.LastName;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = payPalInformation.Order.Enduser.Address.AddressLine;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = payPalInformation.Order.Enduser.Address.AddressLine2;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = payPalInformation.Order.Enduser.Address.City;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = payPalInformation.Order.Enduser.Address.PostalCode;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.GB;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Phone = payPalInformation.Order.Enduser.ContactInformation.Phone;
            #endregion

            PaymentDetailsItemType[] itemArray = new PaymentDetailsItemType[payPalInformation.Order.OrderDetails.Products.Length];
            PaymentDetailsItemType items = null;

            //loop through all the items that were added to the shopping cart.
            for (int i = 0; i < payPalInformation.Order.OrderDetails.Products.Length; i++)
            {
                items = new PaymentDetailsItemType();
                items.Amount = new BasicAmountType();
                items.Amount.Value = payPalInformation.Order.OrderDetails.Products[i].Price.ToString();
                items.Amount.currencyID = CurrencyCodeType.GBP;
                items.Quantity = payPalInformation.Order.OrderDetails.Products[i].Quantity.ToString();

                items.Name = payPalInformation.Order.OrderDetails.Products[i].Name;
                items.Number = payPalInformation.Order.OrderDetails.Products[i].ProductId.ToString();

                itemArray.SetValue(items, i);
            }

            #region set payment details
            //set payment details
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.Custom = System.DateTime.Now.ToLongTimeString();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderDescription = "";

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[itemArray.Length];

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = itemArray;

            for (int ii = 0; ii < itemArray.Length; ii++)
            {
                DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(itemArray[ii], ii);
            }
            #endregion

            #region order summary
            //order summary
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.GBP;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = payPalInformation.Order.OrderTotal.ToString();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal = new BasicAmountType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.currencyID = CurrencyCodeType.GBP;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.Value = payPalInformation.Order.ShippingTotal.ToString();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal = new BasicAmountType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.currencyID = CurrencyCodeType.GBP;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.Value = payPalInformation.Order.Tax.ToString();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal = new BasicAmountType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.currencyID = CurrencyCodeType.GBP;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.Value = payPalInformation.Order.SubTotal.ToString();
            #endregion

            #region set ship to address
            //set ship to address

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress = new AddressType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name = payPalInformation.Order.Enduser.FirstName + " " + payPalInformation.Order.Enduser.LastName;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1 = payPalInformation.Order.ShippingAddress.AddressLine;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName = payPalInformation.Order.ShippingAddress.City;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode = payPalInformation.Order.ShippingAddress.PostalCode;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true;

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country = CountryCodeType.GB;
            #endregion

            //credentials
            DoDirectPaymentReq DoDPReq = new DoDirectPaymentReq();
            DoDPReq.DoDirectPaymentRequest = DoDirectPmtReqType;
            DoDPReq.DoDirectPaymentRequest.Version = "2.20";

            try
            {
                //make call return response
                DoDirectPaymentResponseType DPRes = new DoDirectPaymentResponseType();
                DPRes = PPInterface.DoDirectPayment(DoDPReq);
                string errors = CheckForErrors(DPRes);

                if (errors == string.Empty)
                {
                    IsSubmissionSuccess = true;
                    payPalInformation.Order.TransactionId = DPRes.TransactionID;
                }
                else
                {
                    IsSubmissionSuccess = false;
                    SubmissionError = errors;
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        public PayPalInformation GetExpressCheckoutDetails(PayPalInformation payPalInformation, string token)
        {
            GetExpressCheckoutDetailsResponseType GetECDetailsRes = new GetExpressCheckoutDetailsResponseType();
            GetExpressCheckoutDetailsRequestType GetECDetailsReqType = new GetExpressCheckoutDetailsRequestType();
            GetExpressCheckoutDetailsReq GetECDetailsReq = new GetExpressCheckoutDetailsReq();

            GetECDetailsReqType.Version = "53.0";
            GetECDetailsReqType.Token = token;

            GetECDetailsReq.GetExpressCheckoutDetailsRequest = GetECDetailsReqType;

            PayPalAPIAASoapBinding PPInterface = new PayPalAPIAASoapBinding();
            UserIdPasswordType user = new UserIdPasswordType();
            user.Username = this.APIUsername;
            user.Password = this.APIPassword;
            user.AuthCert = CertPath;

            PPInterface.Url = this.APIPath;
            PPInterface.RequesterCredentials = new CustomSecurityHeaderType();
            PPInterface.RequesterCredentials.Credentials = new UserIdPasswordType();
            PPInterface.RequesterCredentials.Credentials = user;

            FileStream fStream = File.Open(CertPath, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[fStream.Length];

            int count = fStream.Read(buffer, 0, buffer.Length);

            fStream.Close();

            X509Certificate2 x509 = new X509Certificate2(buffer, CertPassword);
            PPInterface.ClientCertificates.Add(x509);
            //PayPalInformation PPInformation = new PayPalInformation();
            GetECDetailsRes = PPInterface.GetExpressCheckoutDetails(GetECDetailsReq);
            if (GetECDetailsRes.Ack == AckCodeType.Success)
            {

                payPalInformation.Order.Enduser.FirstName = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
                payPalInformation.Order.Enduser.LastName = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
                payPalInformation.Order.ShippingAddress.AddressLine = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
                payPalInformation.Order.ShippingAddress.AddressLine2 = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
                payPalInformation.Order.ShippingAddress.City = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
                payPalInformation.Order.ShippingAddress.PostalCode = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                payPalInformation.Order.PayerId = GetECDetailsRes.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            }
            return payPalInformation;
        }
コード例 #10
0
        public OrderInfo DoExpressCheckout(string token, PayPalInformation payPalInformation)
        {
            #region old do express checkout
            DoExpressCheckoutPaymentRequestDetailsType DoECPmtReqDetails = new DoExpressCheckoutPaymentRequestDetailsType();
            DoExpressCheckoutPaymentRequestType DoECReqType = new DoExpressCheckoutPaymentRequestType();
            DoECReqType.DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            DoExpressCheckoutPaymentReq DoECPmtReq = new DoExpressCheckoutPaymentReq();
            DoECPmtReq.DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType();

            DoExpressCheckoutPaymentResponseType DoECPmtRes = new DoExpressCheckoutPaymentResponseType();

            DoECReqType.Version = "2.20";

            DoECPmtReqDetails.Token = token;

            DoECPmtReqDetails.PayerID = payPalInformation.Order.EndUserId.ToString();

            DoECPmtReqDetails.PaymentAction = PaymentActionCodeType.Sale;

            DoECPmtReqDetails.PaymentDetails = new PaymentDetailsType();

            DoECPmtReqDetails.PaymentDetails.OrderDescription = "Talamh Order";

            DoECPmtReqDetails.PayerID = payPalInformation.Order.PayerId;

            DoECPmtReqDetails.PaymentDetails.OrderTotal = new BasicAmountType();

            DoECPmtReqDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.GBP;

            DoECPmtReqDetails.PaymentDetails.OrderTotal.Value = payPalInformation.Order.SubTotal.ToString();

            DoECReqType.DoExpressCheckoutPaymentRequestDetails = DoECPmtReqDetails;

            DoECPmtReq.DoExpressCheckoutPaymentRequest = DoECReqType;

            try
            {
                DoECPmtRes = PPInterface.DoExpressCheckoutPayment(DoECPmtReq);
                string errors = this.CheckForErrors(DoECPmtRes);
                OrderInfo order = new OrderInfo();

                if (errors == String.Empty)
                {
                    order.Ack = DoECPmtRes.Ack.ToString();
                    order.TransactionID = DoECPmtRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID;
                    order.ReceiptID = DoECPmtRes.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.ReceiptID;
                }
                else
                    order.Ack = errors;

                return order;
            }
            catch(Exception ex)
            {
                OrderInfo error = new OrderInfo();
                error.Ack = "ERROR" + ex.ToString();
                return error;
            }
            #endregion
        }