Exemple #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>
        /// Start the paypal payment process. This should return a redirect url in the IPaymentResponse.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private IPaymentResponse BeginExpressCheckout(IPaymentRequest request)
        {
            var response = new PaymentResponse();
            try
            {
                SetExpressCheckoutRequestDetailsType reqDetails = new SetExpressCheckoutRequestDetailsType();

                reqDetails.ReturnURL = request.PaymentSuccessReturnUrl.ToString();
                reqDetails.CancelURL = request.PaymentCancelReturnUrl.ToString();
                reqDetails.NoShipping = "1";

                reqDetails.PaymentAction = PaymentActionCodeType.Sale;
                reqDetails.PaymentActionSpecified = true;
                reqDetails.AllowNote = "0";

                BillingAgreementDetailsType bADT = new BillingAgreementDetailsType()
                {
                    BillingAgreementDescription = string.Empty,
                    BillingType = BillingCodeType.RecurringPayments
                };

                reqDetails.BillingAgreementDetails = new BillingAgreementDetailsType[1];
                reqDetails.BillingAgreementDetails.SetValue(bADT, 0);

                reqDetails.OrderTotal = new BasicAmountType()
                {
                    currencyID = CurrencyCodeType.USD,
                    Value = request.Amount.ToString()
                };
                bADT.BillingAgreementDescription = request.Description;
                reqDetails.OrderDescription = bADT.BillingAgreementDescription;

                SetExpressCheckoutReq req = new SetExpressCheckoutReq()
                {
                    SetExpressCheckoutRequest = new SetExpressCheckoutRequestType()
                    {
                        Version = this._paymentGateway.APIVersion,
                        SetExpressCheckoutRequestDetails = reqDetails
                    }
                };

                SetExpressCheckoutResponseType paypalResp = BuildPayPalWebservice().SetExpressCheckout(req);

                if (paypalResp.Errors != null && paypalResp.Errors.Length > 0)
                {
                    response.IsSuccess = false;
                    response.Message = paypalResp.Errors[0].LongMessage;
                    return response;
                }

                response.RedirectUrl = string.Format("{0}?cmd=_express-checkout&useraction=commit&token={1}", response.RedirectUrl, paypalResp.Token);
                response.RedirectRequested = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.ToString();
                response.IsSuccess = false;
            }
            return response;
        }
Exemple #3
0
 /// <remarks/>
 public void SetExpressCheckoutAsync(SetExpressCheckoutReq SetExpressCheckoutReq) {
     this.SetExpressCheckoutAsync(SetExpressCheckoutReq, null);
 }