/// <summary> /// Do paypal express checkout /// </summary> /// <param name="Token">Paypal express checkout token</param> /// <param name="PayerID">Paypal payer identifier</param> /// <param name="OrderTotal">Order total</param> /// <param name="processPaymentResult">Process payment result</param> public void DoExpressCheckout(string Token, string PayerID, decimal OrderTotal, ProcessPaymentResult processPaymentResult) { InitSettings(); TransactMode transactionMode = GetCurrentTransactionMode(); DoExpressCheckoutPaymentReq req = new DoExpressCheckoutPaymentReq(); DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType(); req.DoExpressCheckoutPaymentRequest = request; request.Version = this.APIVersion; DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType(); request.DoExpressCheckoutPaymentRequestDetails = details; PaymentDetailsType paymentDetails = new PaymentDetailsType(); details.PaymentDetails = paymentDetails; if (transactionMode == TransactMode.Authorize) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } details.Token = Token; details.PayerID = PayerID; paymentDetails.OrderTotal = new BasicAmountType(); paymentDetails.OrderTotal.Value = OrderTotal.ToString("N", new CultureInfo("en-us")); paymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(CurrencyManager.PrimaryStoreCurrency); paymentDetails.ButtonSource = "nopCommerceCart"; DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(req); string error; if (!PaypalHelper.CheckSuccess(response, out error)) { throw new NopException(error); } processPaymentResult.AuthorizationTransactionID = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID; processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString(); //processPaymentResult.AuthorizationDate = response.Timestamp; //processPaymentResult.AuthorizationDate = DateTime.Now; if (transactionMode == TransactMode.Authorize) { processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized; } else { processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid; } }
public DoExpressCheckoutPaymentResponseType DoExpressCheckoutPayment(ProcessPaymentRequest processPaymentRequest) { var result = new DoExpressCheckoutPaymentResponseType(); var settings = CommonServices.Settings.LoadSetting <PayPalExpressPaymentSettings>(processPaymentRequest.StoreId); // populate payment details var paymentDetails = new PaymentDetailsType { OrderTotal = new BasicAmountType { Value = Math.Round(processPaymentRequest.OrderTotal, 2).ToString("N", new CultureInfo("en-us")), currencyID = PayPalHelper.GetPaypalCurrency(_currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)) }, Custom = processPaymentRequest.OrderGuid.ToString(), ButtonSource = SmartStoreVersion.CurrentFullVersion }; // build the request var req = new DoExpressCheckoutPaymentReq { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType { Version = PayPalHelper.GetApiVersion(), DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType { Token = processPaymentRequest.PaypalToken, PayerID = processPaymentRequest.PaypalPayerId, PaymentAction = PayPalHelper.GetPaymentAction(settings), PaymentActionSpecified = true, PaymentDetails = new PaymentDetailsType[] { paymentDetails } } } }; //execute request using (var service = new PayPalAPIAASoapBinding()) { service.Url = PayPalHelper.GetPaypalServiceUrl(settings); service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(settings); result = service.DoExpressCheckoutPayment(req); } return(result); }
/// <summary> /// Do paypal express checkout /// </summary> /// <param name="paymentInfo">Payment info required for an order processing</param> /// <param name="orderGuid">Unique order identifier</param> /// <param name="processPaymentResult">Process payment result</param> public void DoExpressCheckout(PaymentInfo paymentInfo, Guid orderGuid, ProcessPaymentResult processPaymentResult) { InitSettings(); TransactMode transactionMode = GetCurrentTransactionMode(); DoExpressCheckoutPaymentReq req = new DoExpressCheckoutPaymentReq(); DoExpressCheckoutPaymentRequestType request = new DoExpressCheckoutPaymentRequestType(); req.DoExpressCheckoutPaymentRequest = request; request.Version = this.APIVersion; DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType(); request.DoExpressCheckoutPaymentRequestDetails = details; if (transactionMode == TransactMode.Authorize) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } details.PaymentActionSpecified = true; details.Token = paymentInfo.PaypalToken; details.PayerID = paymentInfo.PaypalPayerId; details.PaymentDetails = new PaymentDetailsType[1]; PaymentDetailsType paymentDetails1 = new PaymentDetailsType(); details.PaymentDetails[0] = paymentDetails1; paymentDetails1.OrderTotal = new BasicAmountType(); paymentDetails1.OrderTotal.Value = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us")); paymentDetails1.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency); paymentDetails1.Custom = orderGuid.ToString(); paymentDetails1.ButtonSource = "nopCommerceCart"; DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(req); string error; if (!PaypalHelper.CheckSuccess(response, out error)) { throw new NopException(error); } if (response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo != null && response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0] != null) { processPaymentResult.AuthorizationTransactionId = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID; processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString(); if (transactionMode == TransactMode.Authorize) { processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized; } else { processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid; } } else { throw new NopException("response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo is null"); } }