private int GetSubscriptionPeriod(RecurringPaymentRequest paymentRequest) { var durationInSeconds = 0; switch (paymentRequest.DurationUnit) { case DurationUnit.Day: durationInSeconds = paymentRequest.DurationBetweenEachRecurrence * 86400; break; case DurationUnit.Week: durationInSeconds = paymentRequest.DurationBetweenEachRecurrence * 604800; break; case DurationUnit.Month: var toDate = paymentRequest.EffectiveFrom.AddMonths(paymentRequest.DurationBetweenEachRecurrence); durationInSeconds = Convert.ToInt32(toDate.Subtract(paymentRequest.EffectiveFrom).TotalSeconds); break; case DurationUnit.Year: var start = new DateTime(paymentRequest.EffectiveFrom.Year, paymentRequest.EffectiveFrom.Month, paymentRequest.EffectiveFrom.Day); var end = start.AddYears(paymentRequest.DurationBetweenEachRecurrence); durationInSeconds = Convert.ToInt32(end.Subtract(start).TotalSeconds); break; default: durationInSeconds = paymentRequest.DurationBetweenEachRecurrence; break; } return(durationInSeconds); }
/// <summary> /// Method creates Recurring Payment Action Request /// </summary> /// <returns></returns> private static String doRecurringPaymentActionRequest() { //RecurringPayment RecurringPaymentRequest oRecurringPaymentRequest = new RecurringPaymentRequest(); IPGApiActionRequest oIPGApiActionRequest = oRecurringPaymentRequest.RecurringPaymentActionRequest; return(SendActionRequest(oIPGApiActionRequest)); }
private SppContainer <Product> CreateSchibstedProduct(RecurringPaymentRequest paymentRequest) { var paymentMethod = paymentRequest.PaymentMethod; string clientSecret = paymentMethod.DynamicProperty <string>().ClientSecret; string clientId = paymentMethod.DynamicProperty <string>().ClientId; string paymentOptions = paymentMethod.DynamicProperty <string>().PaymentOptions; ServerToken = SchibstedUtil.GetServerToken(clientId, clientSecret); var productName = string.Join(", ", paymentRequest.PurchaseOrder.OrderLines.Select(x => x.ProductName)); if (productName.Length > 64) { productName = productName.Substring(0, 64); } var postValues = new Dictionary <string, string>() { { "oauth_token", ServerToken.AccessToken }, { "type", "2" }, { "code", paymentRequest.Payment.ReferenceId }, { "name", HttpUtility.UrlEncode(productName) }, { "description", "Subscription: " + paymentRequest.Payment.ReferenceId }, { "price", Convert.ToInt32(paymentRequest.PurchaseOrder.OrderTotal * 100).ToString() }, { "vat", Convert.ToInt32(paymentRequest.PaymentMethod.FeePercent * 10000).ToString() }, { "currency", paymentRequest.PurchaseOrder.BillingCurrency.ISOCode }, { "paymentOptions", paymentOptions }, { "subscriptionPeriod", GetSubscriptionPeriod(paymentRequest).ToString() }, { "subscriptionAutoRenew", paymentRequest.Recurs ? "1" : "0" } }; try { return(SchibstedUtil.SchibstedApiPost <Product>("/product", postValues)); } catch (WebException ex) { LogWebException(ex); throw new Exception("API Error, see log for details"); } }
private void ValidateRecurrencePerPayPalRules(RecurringPaymentRequest recurringRequest) { if (recurringRequest.DurationBetweenEachRecurrence < 1) { throw new NotSupportedException("Duration between each recurrence must be greater than 1 regardless of the duration unit. Please set DurationBetweenEachRecurrence accordingly on your recurring payment request."); } switch (recurringRequest.DurationUnit) { case DurationUnit.Day: if (recurringRequest.DurationBetweenEachRecurrence > 90) { throw new NotSupportedException("Duration between each recurrence must be between 1 and 90 days."); } break; case DurationUnit.Week: if (recurringRequest.DurationBetweenEachRecurrence > 52) { throw new NotSupportedException("Duration between each recurrence must be between 1 and 52 weeks."); } break; case DurationUnit.Month: if (recurringRequest.DurationBetweenEachRecurrence > 24) { throw new NotSupportedException("Duration between each recurrence must be between 1 and 24 months."); } break; case DurationUnit.Year: if (recurringRequest.DurationBetweenEachRecurrence > 5) { throw new NotSupportedException("Duration between each recurrence must be between 1 and 5 years."); } break; } }