public PayPal() { PayPalController.GetPaypalRequirements(out IPayPalRefund, out IPayPal); }
public static String MakeECRecurringProfile(ShoppingCart cart, int orderNumber, String payPalToken, String payerID, DateTime nextRecurringShipDate) { PayPalAPISoapBinding IPayPalRefund; PayPalAPIAASoapBinding IPayPal; PayPalController.GetPaypalRequirements(out IPayPalRefund, out IPayPal); String result = String.Empty; CreateRecurringPaymentsProfileReq ECRecurringRequest = new CreateRecurringPaymentsProfileReq(); CreateRecurringPaymentsProfileRequestType varECRequest = new CreateRecurringPaymentsProfileRequestType(); CreateRecurringPaymentsProfileRequestDetailsType varECRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType(); CreateRecurringPaymentsProfileResponseType ECRecurringResponse = new CreateRecurringPaymentsProfileResponseType(); //Re-Use the Internal Gateway Recurring Billing logic for calculating how much of the order is recurring ShoppingCart cartRecur = new ShoppingCart(cart.ThisCustomer.SkinID, cart.ThisCustomer, CartTypeEnum.RecurringCart, orderNumber, false); Decimal CartTotalRecur = Decimal.Round(cartRecur.Total(true), 2, MidpointRounding.AwayFromZero); Decimal RecurringAmount = CartTotalRecur - CommonLogic.IIF(cartRecur.Coupon.CouponType == CouponTypeEnum.GiftCard, CommonLogic.IIF(CartTotalRecur < cartRecur.Coupon.DiscountAmount, CartTotalRecur, cartRecur.Coupon.DiscountAmount), 0); DateIntervalTypeEnum ecRecurringIntervalType = cartRecur.CartItems[0].RecurringIntervalType; //We currently only support 1 interval per recurring order, so grabbing the first as a default should be safe int ecRecurringInterval = cartRecur.CartItems[0].RecurringInterval; BasicAmountType ecRecurringAmount = new BasicAmountType(); ecRecurringAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true); ecRecurringAmount.Value = RecurringAmount.ToString(); BillingPeriodDetailsType varECSchedulePaymentDetails = GetECRecurringPeriodDetails(ecRecurringIntervalType, ecRecurringInterval); varECSchedulePaymentDetails.Amount = ecRecurringAmount; varECSchedulePaymentDetails.TotalBillingCyclesSpecified = false; ScheduleDetailsType varECSchedule = new ScheduleDetailsType(); //Need a better description, but it must match the one sent in StartEC varECSchedule.Description = "Recurring order created on " + System.DateTime.Now.ToShortDateString() + " from " + AppLogic.AppConfig("StoreName"); varECSchedule.MaxFailedPayments = 0; //Cancel the order if a recurrence fails varECSchedule.MaxFailedPaymentsSpecified = true; varECSchedule.AutoBillOutstandingAmount = AutoBillType.NoAutoBill; varECSchedule.AutoBillOutstandingAmountSpecified = true; varECSchedule.PaymentPeriod = varECSchedulePaymentDetails; RecurringPaymentsProfileDetailsType varECProfileDetails = new RecurringPaymentsProfileDetailsType(); varECProfileDetails.SubscriberName = cart.ThisCustomer.FirstName + " " + cart.ThisCustomer.LastName; varECProfileDetails.BillingStartDate = nextRecurringShipDate; varECRequestDetails.ScheduleDetails = varECSchedule; varECRequestDetails.Token = payPalToken; varECRequestDetails.RecurringPaymentsProfileDetails = varECProfileDetails; if (cart.IsAllDownloadComponents()) { PaymentDetailsItemType varECPaymentDetails = new PaymentDetailsItemType(); varECPaymentDetails.ItemCategory = ItemCategoryType.Digital; varECPaymentDetails.ItemCategorySpecified = true; List <PaymentDetailsItemType> ECPaymentDetailsList = new List <PaymentDetailsItemType>(); ECPaymentDetailsList.Add(varECPaymentDetails); varECRequestDetails.PaymentDetailsItem = ECPaymentDetailsList.ToArray(); } varECRequest.Version = API_VER; varECRequest.CreateRecurringPaymentsProfileRequestDetails = varECRequestDetails; ECRecurringRequest.CreateRecurringPaymentsProfileRequest = varECRequest; ECRecurringResponse = IPayPal.CreateRecurringPaymentsProfile(ECRecurringRequest); if (ECRecurringResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase)) { result = AppLogic.ro_OK; } else { if (ECRecurringResponse.Errors != null) { bool first = true; for (int ix = 0; ix < ECRecurringResponse.Errors.Length; ix++) { if (!first) { result += ", "; } result += ECRecurringResponse.Errors[ix].LongMessage; first = false; } } } //Log the transaction OrderTransactionCollection ecRecurringOrderTransaction = new OrderTransactionCollection(orderNumber); ecRecurringOrderTransaction.AddTransaction("PayPal Express Checkout Recurring Profile Creation", ECRecurringRequest.ToString(), result, payerID, //PNREF = payerID (ECRecurringResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : ECRecurringResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID), //Code = ProfileID AppLogic.ro_PMPayPalExpress, null, RecurringAmount); return(result); }
public static String CancelECRecurringProfile(int OriginalOrderNumber) { PayPalAPISoapBinding IPayPalRefund; PayPalAPIAASoapBinding IPayPal; PayPalController.GetPaypalRequirements(out IPayPalRefund, out IPayPal); String profileID = String.Empty; String result = String.Empty; profileID = GetPPECProfileID(OriginalOrderNumber); if (profileID != String.Empty) { ManageRecurringPaymentsProfileStatusReq ECRecurringCancelRequest = new ManageRecurringPaymentsProfileStatusReq(); ManageRecurringPaymentsProfileStatusRequestType varECRecurringRequest = new ManageRecurringPaymentsProfileStatusRequestType(); ManageRecurringPaymentsProfileStatusRequestDetailsType varECRecurringRequestDetails = new ManageRecurringPaymentsProfileStatusRequestDetailsType(); ManageRecurringPaymentsProfileStatusResponseType varECRecurringResponse = new ManageRecurringPaymentsProfileStatusResponseType(); varECRecurringRequestDetails.Action = StatusChangeActionType.Cancel; varECRecurringRequestDetails.ProfileID = profileID; varECRecurringRequest.ManageRecurringPaymentsProfileStatusRequestDetails = varECRecurringRequestDetails; varECRecurringRequest.Version = API_VER; ECRecurringCancelRequest.ManageRecurringPaymentsProfileStatusRequest = varECRecurringRequest; varECRecurringResponse = IPayPal.ManageRecurringPaymentsProfileStatus(ECRecurringCancelRequest); if (varECRecurringResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase)) { result = AppLogic.ro_OK; } else { if (varECRecurringResponse.Errors != null) { bool first = true; for (int ix = 0; ix < varECRecurringResponse.Errors.Length; ix++) { if (!first) { result += ", "; } result += varECRecurringResponse.Errors[ix].LongMessage; first = false; } } } } else { result = "No matching ProfileID found for that order number"; SysLog.LogMessage("An attempt was made to cancel a PayPal express recurring order with no matching ProfileID", "Original order ID was: " + OriginalOrderNumber.ToString(), MessageTypeEnum.Informational, MessageSeverityEnum.Alert); } return(result); }
public static String ProcessEC(ShoppingCart cart, decimal OrderTotal, int OrderNumber, String PayPalToken, String PayerID, String TransactionMode, out String AuthorizationResult, out String AuthorizationTransID) { PayPalAPISoapBinding IPayPalRefund; PayPalAPIAASoapBinding IPayPal; PayPalController.GetPaypalRequirements(out IPayPalRefund, out IPayPal); String result = String.Empty; AuthorizationResult = String.Empty; AuthorizationTransID = String.Empty; DoExpressCheckoutPaymentReq ECRequest = new DoExpressCheckoutPaymentReq(); DoExpressCheckoutPaymentRequestType varECRequest = new DoExpressCheckoutPaymentRequestType(); DoExpressCheckoutPaymentRequestDetailsType varECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType(); DoExpressCheckoutPaymentResponseType ECResponse = new DoExpressCheckoutPaymentResponseType(); DoExpressCheckoutPaymentResponseDetailsType varECResponse = new DoExpressCheckoutPaymentResponseDetailsType(); ECRequest.DoExpressCheckoutPaymentRequest = varECRequest; varECRequest.DoExpressCheckoutPaymentRequestDetails = varECRequestDetails; ECResponse.DoExpressCheckoutPaymentResponseDetails = varECResponse; varECRequestDetails.Token = PayPalToken; varECRequestDetails.PayerID = PayerID; varECRequestDetails.PaymentAction = PaymentActionCodeType.Authorization; if (TransactionMode == AppLogic.ro_TXModeAuthCapture || AppLogic.AppConfigBool("PayPal.ForceCapture") || PayPalController.GetAppropriateExpressType() == ExpressAPIType.PayPalAcceleratedBording) { varECRequestDetails.PaymentAction = PaymentActionCodeType.Sale; } varECRequestDetails.PaymentActionSpecified = true; PaymentDetailsType ECPaymentDetails = new PaymentDetailsType(); BasicAmountType ECPaymentOrderTotal = new BasicAmountType(); ECPaymentOrderTotal.Value = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal); ECPaymentOrderTotal.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true); ECPaymentDetails.InvoiceID = OrderNumber.ToString(); ECPaymentDetails.Custom = cart.ThisCustomer.CustomerID.ToString(); ECPaymentDetails.ButtonSource = PayPalController.BN + "_EC_US"; ECPaymentDetails.NotifyURL = AppLogic.GetStoreHTTPLocation(true) + AppLogic.AppConfig("PayPal.NotificationURL"); varECRequest.Version = API_VER; ECPaymentDetails.OrderTotal = ECPaymentOrderTotal; List <PaymentDetailsType> ECPaymentDetailsList = new List <PaymentDetailsType>(); ECPaymentDetailsList.Add(ECPaymentDetails); varECRequestDetails.PaymentDetails = ECPaymentDetailsList.ToArray(); ECResponse = IPayPal.DoExpressCheckoutPayment(ECRequest); if (ECResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase)) { AuthorizationTransID = CommonLogic.IIF(varECRequestDetails.PaymentAction == PaymentActionCodeType.Sale, "CAPTURE=", "AUTH=") + ECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID; result = AppLogic.ro_OK; AuthorizationResult = ECResponse.Ack.ToString(); SetECFaultRedirect(cart.ThisCustomer, string.Empty); } else { if (ECResponse.Errors != null) { if (ECResponse.Errors.Any(e => e.ErrorCode == ECFaultRedirectErrorCode.ToString())) { // Express Checkout failed funding recovery feature returns a 10486 which signifies that // the user should be redirected back to paypal. result = AuthorizationResult = AppLogic.ro_PMPayPalExpressRedirect; } else { result = AuthorizationResult = string.Join(",", ECResponse.Errors.Select(e => e.LongMessage).ToArray()); } } } return(result); }