示例#1
0
 /// <remarks/>
 public void SetExpressCheckoutAsync(SetExpressCheckoutReq SetExpressCheckoutReq, object userState) {
     if ((this.SetExpressCheckoutOperationCompleted == null)) {
         this.SetExpressCheckoutOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetExpressCheckoutOperationCompleted);
     }
     this.InvokeAsync("SetExpressCheckout", new object[] {
                 SetExpressCheckoutReq}, this.SetExpressCheckoutOperationCompleted, userState);
 }
        /// <summary>
        /// Returns a token from PayPal.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="returnUrl">The return URL.</param>
        /// <param name="cancelUrl">The cancel URL.</param>
        /// <param name="authorizeOnly">if set to <c>true</c> [authorize only].</param>
        /// <returns>string</returns>
        internal string SetExpressCheckout(Order order, string returnUrl, string cancelUrl, bool authorizeOnly)
        {
            Validator.ValidateStringArgumentIsNotNullOrEmptyString(returnUrl, RETURN_URL);
              Validator.ValidateStringArgumentIsNotNullOrEmptyString(cancelUrl, CANCEL_URL);

              string token = string.Empty;
              string url = string.Empty;

              SetExpressCheckoutReq expressCheckoutRequest = new SetExpressCheckoutReq();
              SetExpressCheckoutRequestDetailsType expressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
              expressCheckoutRequest.SetExpressCheckoutRequest = new SetExpressCheckoutRequestType();
              expressCheckoutRequest.SetExpressCheckoutRequest.Version = PayPalServiceUtility.PayPalVersionNumber;

              //Set the Shipping Address
              if(order.ShippingAddress != null) {
            expressCheckoutRequestDetails.Address = new PayPalSvc.AddressType();
            expressCheckoutRequestDetails.Address.Name = order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName;
            expressCheckoutRequestDetails.Address.Street1 = order.ShippingAddress.Address1;
            expressCheckoutRequestDetails.Address.Street2 = order.ShippingAddress.Address2;
            expressCheckoutRequestDetails.Address.CityName = order.ShippingAddress.City;
            expressCheckoutRequestDetails.Address.StateOrProvince = order.ShippingAddress.StateOrRegion;
            expressCheckoutRequestDetails.Address.PostalCode = order.ShippingAddress.PostalCode;
            expressCheckoutRequestDetails.Address.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), order.ShippingAddress.Country);
            expressCheckoutRequestDetails.Address.CountrySpecified = true;
              }

              if(order.BillingAddress != null) {
            expressCheckoutRequestDetails.BuyerEmail = order.BillingAddress.Email;
              }
              Currency currency = new Currency();
              decimal total = GetOrderTotal(currency, order);
              expressCheckoutRequestDetails.OrderTotal = GetBasicAmount(total);
              expressCheckoutRequestDetails.ReturnURL = returnUrl;
              expressCheckoutRequestDetails.CancelURL = cancelUrl;
              if(authorizeOnly) {
            expressCheckoutRequestDetails.PaymentAction = PaymentActionCodeType.Authorization;
              }
              else {
            expressCheckoutRequestDetails.PaymentAction = PaymentActionCodeType.Sale;
              }
              expressCheckoutRequestDetails.PaymentActionSpecified = true;
              expressCheckoutRequestDetails.Custom = order.OrderNumber;
              expressCheckoutRequestDetails.InvoiceID = order.OrderNumber;

              expressCheckoutRequest.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails = expressCheckoutRequestDetails;
              SetExpressCheckoutResponseType expressCheckoutResponse =
            payPalAPIAASoapBinding.SetExpressCheckout(expressCheckoutRequest);

              string errorList = ValidateResponse(expressCheckoutResponse);
              //if(expressCheckoutResponse.Ack != AckCodeType.Success && expressCheckoutResponse.Ack != AckCodeType.SuccessWithWarning) {
              if(IsValidResponse(expressCheckoutResponse.Ack)) {
            if (!string.IsNullOrEmpty(errorList)) {
              throw new PayPalServiceException(errorList);
            }
              }

              token = expressCheckoutResponse.Token;
              url = PayPalServiceUtility.GetExpressCheckoutUrl(this.IsLive, token);
              return url;
        }
示例#3
0
 /// <remarks/>
 public void SetExpressCheckoutAsync(SetExpressCheckoutReq SetExpressCheckoutReq) {
     this.SetExpressCheckoutAsync(SetExpressCheckoutReq, null);
 }