/// <remarks/> public void CreateRecurringPaymentsProfileAsync(CreateRecurringPaymentsProfileReq CreateRecurringPaymentsProfileReq) { this.CreateRecurringPaymentsProfileAsync(CreateRecurringPaymentsProfileReq, null); }
/// <remarks/> public void CreateRecurringPaymentsProfileAsync(CreateRecurringPaymentsProfileReq CreateRecurringPaymentsProfileReq, object userState) { if ((this.CreateRecurringPaymentsProfileOperationCompleted == null)) { this.CreateRecurringPaymentsProfileOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateRecurringPaymentsProfileOperationCompleted); } this.InvokeAsync("CreateRecurringPaymentsProfile", new object[] { CreateRecurringPaymentsProfileReq}, this.CreateRecurringPaymentsProfileOperationCompleted, userState); }
/// <summary> /// Process recurring payment /// </summary> /// <param name="paymentInfo">Payment info required for an order processing</param> /// <param name="customer">Customer</param> /// <param name="orderGuid">Unique order identifier</param> /// <param name="processPaymentResult">Process payment result</param> public void ProcessRecurringPayment(PaymentInfo paymentInfo, Customer customer, Guid orderGuid, ref ProcessPaymentResult processPaymentResult) { InitSettings(); CreateRecurringPaymentsProfileReq req = new CreateRecurringPaymentsProfileReq(); req.CreateRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType(); req.CreateRecurringPaymentsProfileRequest.Version = this.APIVersion; CreateRecurringPaymentsProfileRequestDetailsType details = new CreateRecurringPaymentsProfileRequestDetailsType(); req.CreateRecurringPaymentsProfileRequest.CreateRecurringPaymentsProfileRequestDetails = details; details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CreditCardNumber = paymentInfo.CreditCardNumber; details.CreditCard.CreditCardType = GetPaypalCreditCardType(paymentInfo.CreditCardType); details.CreditCard.ExpMonthSpecified = true; details.CreditCard.ExpMonth = paymentInfo.CreditCardExpireMonth; details.CreditCard.ExpYearSpecified = true; details.CreditCard.ExpYear = paymentInfo.CreditCardExpireYear; details.CreditCard.CVV2 = paymentInfo.CreditCardCvv2; details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country); details.CreditCard.CreditCardTypeSpecified = true; details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = paymentInfo.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = paymentInfo.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = paymentInfo.BillingAddress.City; if (paymentInfo.BillingAddress.StateProvince != null) details.CreditCard.CardOwner.Address.StateOrProvince = paymentInfo.BillingAddress.StateProvince.Abbreviation; else details.CreditCard.CardOwner.Address.StateOrProvince = "CA"; details.CreditCard.CardOwner.Address.Country = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country); details.CreditCard.CardOwner.Address.PostalCode = paymentInfo.BillingAddress.ZipPostalCode; details.CreditCard.CardOwner.Payer = paymentInfo.BillingAddress.Email; details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.CreditCard.CardOwner.PayerName.FirstName = paymentInfo.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = paymentInfo.BillingAddress.LastName; //start date details.RecurringPaymentsProfileDetails = new RecurringPaymentsProfileDetailsType(); details.RecurringPaymentsProfileDetails.BillingStartDate = DateTime.UtcNow; details.RecurringPaymentsProfileDetails.ProfileReference = orderGuid.ToString(); //schedule details.ScheduleDetails = new ScheduleDetailsType(); details.ScheduleDetails.Description = string.Format("{0} - {1}", IoC.Resolve<ISettingManager>().StoreName, "recurring payment"); details.ScheduleDetails.PaymentPeriod = new BillingPeriodDetailsType(); details.ScheduleDetails.PaymentPeriod.Amount = new BasicAmountType(); details.ScheduleDetails.PaymentPeriod.Amount.Value = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us")); details.ScheduleDetails.PaymentPeriod.Amount.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency); details.ScheduleDetails.PaymentPeriod.BillingFrequency = paymentInfo.RecurringCycleLength; switch (paymentInfo.RecurringCyclePeriod) { case (int)RecurringProductCyclePeriodEnum.Days: details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Day; break; case (int)RecurringProductCyclePeriodEnum.Weeks: details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Week; break; case (int)RecurringProductCyclePeriodEnum.Months: details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Month; break; case (int)RecurringProductCyclePeriodEnum.Years: details.ScheduleDetails.PaymentPeriod.BillingPeriod = BillingPeriodType.Year; break; default: throw new NopException("Not supported cycle period"); } details.ScheduleDetails.PaymentPeriod.TotalBillingCycles = paymentInfo.RecurringTotalCycles; details.ScheduleDetails.PaymentPeriod.TotalBillingCyclesSpecified = true; CreateRecurringPaymentsProfileResponseType response = service2.CreateRecurringPaymentsProfile(req); string error = string.Empty; bool Success = PaypalHelper.CheckSuccess(response, out error); if (Success) { processPaymentResult.PaymentStatus = PaymentStatusEnum.Pending; if (response.CreateRecurringPaymentsProfileResponseDetails != null) { processPaymentResult.SubscriptionTransactionId = response.CreateRecurringPaymentsProfileResponseDetails.ProfileID; } } else { processPaymentResult.Error = error; processPaymentResult.FullError = error; } }