Beispiel #1
0
 /// <remarks/>
 public void DoDirectPaymentAsync(DoDirectPaymentReq DoDirectPaymentReq) {
     this.DoDirectPaymentAsync(DoDirectPaymentReq, null);
 }
Beispiel #2
0
 /// <remarks/>
 public void DoDirectPaymentAsync(DoDirectPaymentReq DoDirectPaymentReq, object userState) {
     if ((this.DoDirectPaymentOperationCompleted == null)) {
         this.DoDirectPaymentOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDoDirectPaymentOperationCompleted);
     }
     this.InvokeAsync("DoDirectPayment", new object[] {
                 DoDirectPaymentReq}, this.DoDirectPaymentOperationCompleted, userState);
 }
        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;
            }
        }