CreateRecurringPaymentsProfile() public method

public CreateRecurringPaymentsProfile ( CreateRecurringPaymentsProfileReq createRecurringPaymentsProfileReq ) : CreateRecurringPaymentsProfileResponseType
createRecurringPaymentsProfileReq PayPal.PayPalAPIInterfaceService.Model.CreateRecurringPaymentsProfileReq
return PayPal.PayPalAPIInterfaceService.Model.CreateRecurringPaymentsProfileResponseType
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            CreateRecurringPaymentsProfileRequestType request = new CreateRecurringPaymentsProfileRequestType();
            populateRequest(request);

            // Invoke the API
            CreateRecurringPaymentsProfileReq wrapper = new CreateRecurringPaymentsProfileReq();
            wrapper.CreateRecurringPaymentsProfileRequest = request;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            // # API call
            // Invoke the CreateRecurringPaymentsProfile method in service wrapper object
            CreateRecurringPaymentsProfileResponseType createRPProfileResponse = service.CreateRecurringPaymentsProfile(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, createRPProfileResponse);
        }
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            CreateRecurringPaymentsProfileRequestType request = new CreateRecurringPaymentsProfileRequestType();
            populateRequest(request);

            // Invoke the API
            CreateRecurringPaymentsProfileReq wrapper = new CreateRecurringPaymentsProfileReq();
            wrapper.CreateRecurringPaymentsProfileRequest = request;
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
            CreateRecurringPaymentsProfileResponseType createRPProfileResponse = service.CreateRecurringPaymentsProfile(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, createRPProfileResponse);
        }
        /// <summary>
        /// Handles Create Recurring Payments Profile
        /// </summary>
        /// <param name="contextHttp"></param>
        private void CreateRecurringPaymentsProfile(HttpContext contextHttp)
        {
            NameValueCollection parameters = contextHttp.Request.Params;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            CreateRecurringPaymentsProfileReq req = new CreateRecurringPaymentsProfileReq();
            CreateRecurringPaymentsProfileRequestType reqType = new CreateRecurringPaymentsProfileRequestType();

            // (Required) The date when billing for this profile begins.
            // Note:
            // The profile may take up to 24 hours for activation.
            // Character length and limitations: Must be a valid date, in UTC/GMT format
            RecurringPaymentsProfileDetailsType profileDetails = new RecurringPaymentsProfileDetailsType(parameters["billingStartDate"] + "T00:00:00:000Z");

            // Populate schedule details
            ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();

             // (Required) Description of the recurring payment.
             // Note:
             // You must ensure that this field matches the corresponding billing agreement
             // description included in the SetExpressCheckout request.
             // Character length and limitations: 127 single-byte alphanumeric characters
            scheduleDetails.Description = parameters["profileDescription"];

            // (Optional) Number of scheduled payments that can fail before the profile
            // is automatically suspended. An IPN message is sent to the merchant when the
            // specified number of failed payments is reached.
            // Character length and limitations: Number string representing an integer
            if (parameters["maxFailedPayments"] != string.Empty)
            {
                scheduleDetails.MaxFailedPayments = Convert.ToInt32(parameters["maxFailedPayments"]);
            }

            // (Optional) Indicates whether you would like PayPal to automatically bill
            // the outstanding balance amount in the next billing cycle.
            // The outstanding balance is the total amount of any previously failed
            // scheduled payments that have yet to be successfully paid.
            // It is one of the following values:
            // NoAutoBill – PayPal does not automatically bill the outstanding balance.
            // AddToNextBilling – PayPal automatically bills the outstanding balance.
            if (parameters["autoBillOutstandingAmount"] != string.Empty)
            {
                scheduleDetails.AutoBillOutstandingAmount = (AutoBillType)Enum.Parse(typeof(AutoBillType), parameters["autoBillOutstandingAmount"]);
            }

            CurrencyCodeType currency = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), "USD");

            if (parameters["trialBillingAmount"] != string.Empty)
            {
                // Number of billing periods that make up one billing cycle;
                // required if you specify an optional trial period.
                // The combination of billing frequency and billing period must be
                // less than or equal to one year. For example, if the billing cycle is Month,
                // the maximum value for billing frequency is 12. Similarly,
                // if the billing cycle is Week, the maximum value for billing frequency is 52.
                // Note:
                // If the billing period is SemiMonth, the billing frequency must be 1.
                int frequency = Convert.ToInt32(parameters["trialBillingFrequency"]);

                // Billing amount for each billing cycle during this payment period;
                // required if you specify an optional trial period.
                // This amount does not include shipping and tax amounts.
                // Note:
                // All amounts in the CreateRecurringPaymentsProfile request must have
                // the same currency.
                // Character length and limitations:
                // Value is a positive number which cannot exceed $10,000 USD in any currency.
                // It includes no currency symbol.
                // It must have 2 decimal places, the decimal separator must be a period (.),
                // and the optional thousands separator must be a comma (,).
                BasicAmountType paymentAmount = new BasicAmountType(currency, parameters["trialBillingAmount"]);

                // Unit for billing during this subscription period;
                // required if you specify an optional trial period.
                // It is one of the following values: [Day, Week, SemiMonth, Month, Year]
                // For SemiMonth, billing is done on the 1st and 15th of each month.
                // Note:
                // The combination of BillingPeriod and BillingFrequency cannot exceed one year.
                BillingPeriodType period = (BillingPeriodType)Enum.Parse(typeof(BillingPeriodType), parameters["trialBillingPeriod"]);

                // Number of billing periods that make up one billing cycle;
                // required if you specify an optional trial period.
                // The combination of billing frequency and billing period must be
                // less than or equal to one year. For example, if the billing cycle is Month,
                // the maximum value for billing frequency is 12. Similarly,
                // if the billing cycle is Week, the maximum value for billing frequency is 52.
                // Note:
                // If the billing period is SemiMonth, the billing frequency must be 1.
                int numCycles = Convert.ToInt32(parameters["trialBillingCycles"]);

                BillingPeriodDetailsType trialPeriod = new BillingPeriodDetailsType(period, frequency, paymentAmount);
                trialPeriod.TotalBillingCycles = numCycles;
                scheduleDetails.TrialPeriod = trialPeriod;
            }

            if (parameters["billingAmount"] != string.Empty)
            {
                // (Required) Number of billing periods that make up one billing cycle.
                // The combination of billing frequency and billing period must be less than
                // or equal to one year. For example, if the billing cycle is Month,
                // the maximum value for billing frequency is 12. Similarly,
                // if the billing cycle is Week, the maximum value for billing frequency is 52.
                // Note:
                // If the billing period is SemiMonth, the billing frequency must be 1.
                int frequency = Convert.ToInt32(parameters["billingFrequency"]);

                // (Required) Billing amount for each billing cycle during this payment period.
                // This amount does not include shipping and tax amounts.
                // Note:
                // All amounts in the CreateRecurringPaymentsProfile request must have the same
                // currency.
                // Character length and limitations: Value is a positive number which cannot
                // exceed $10,000 USD in any currency. It includes no currency symbol.
                // It must have 2 decimal places, the decimal separator must be a period (.),
                // and the optional thousands separator must be a comma (,).
                BasicAmountType paymentAmount = new BasicAmountType(currency, parameters["billingAmount"]);

                // (Required) Unit for billing during this subscription period.
                // It is one of the following values:
                // [Day, Week, SemiMonth, Month, Year]
                // For SemiMonth, billing is done on the 1st and 15th of each month.
                // Note:
                // The combination of BillingPeriod and BillingFrequency cannot exceed one year.
                BillingPeriodType period = (BillingPeriodType)Enum.Parse(typeof(BillingPeriodType), parameters["billingPeriod"]);

                 // (Optional) Number of billing cycles for payment period.
                 // For the regular payment period, if no value is specified or the value is 0,
                 // the regular payment period continues until the profile is canceled or deactivated.
                 // For the regular payment period, if the value is greater than 0,
                 // the regular payment period will expire after the trial period is
                 // finished and continue at the billing frequency for TotalBillingCycles cycles.
                int numCycles = Convert.ToInt32(parameters["totalBillingCycles"]);

                BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(period, frequency, paymentAmount);
                paymentPeriod.TotalBillingCycles = numCycles;
                scheduleDetails.PaymentPeriod = paymentPeriod;
            }

            CreateRecurringPaymentsProfileRequestDetailsType reqDetails = new CreateRecurringPaymentsProfileRequestDetailsType(profileDetails, scheduleDetails);

            // Credit Card Number is required for CreateRecurringPaymentsProfile.
            // Each CreateRecurringPaymentsProfile request creates a single recurring payments profile.
            CreditCardDetailsType cc = new CreditCardDetailsType();

            // (Required) Credit Card Number.
            // Character length and limitations: Numeric characters only with no spaces
            // or punctuation. The string must conform with modulo and length required
            // by each credit card type.
            cc.CreditCardNumber = parameters["creditCardNumber"];

            // Card Verification Value, version 2.
            // Your Merchant Account settings determine whether this field is required.
            // To comply with credit card processing regulations, you must not store this
            // value after a transaction has been completed.
            // Character length and limitations:
            // For Visa, MasterCard, and Discover, the value is exactly 3 digits.
            // For American Express, the value is exactly 4 digits.
            cc.CVV2 = parameters["cvv"];

            // Expiry Month
            cc.ExpMonth = Convert.ToInt32(parameters["expMonth"]);

            // Expiry Year
            cc.ExpYear = Convert.ToInt32(parameters["expYear"]);

            // (Optional) Type of credit card.
            // For UK, only Maestro, MasterCard, Discover, and Visa are allowable.
            // For Canada, only MasterCard and Visa are allowable and
            // Interac debit cards are not supported. It is one of the following values:
            // [Visa, MasterCard, Discover, Amex, Maestro: See note.]
            // Note:
            // If the credit card type is Maestro, you must set CURRENCYCODE to GBP.
            // In addition, you must specify either STARTDATE or ISSUENUMBER.
            CreditCardTypeType type = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), parameters["creditCardType"]);
            cc.CreditCardType = type;

            reqDetails.CreditCard = cc;

            reqType.CreateRecurringPaymentsProfileRequestDetails = reqDetails;
            req.CreateRecurringPaymentsProfileRequest = reqType;

            CreateRecurringPaymentsProfileResponseType response = null;
            try
            {
                response = service.CreateRecurringPaymentsProfile(req);
            }
            catch (System.Exception ex)
            {
                contextHttp.Response.Write(ex.Message);
                return;
            }

            Dictionary<string, string> responseValues = new Dictionary<string, string>();
            string redirectUrl = null;

            responseValues.Add("Acknowledgement", response.Ack.ToString());

            Display(contextHttp, "CreateRecurringPaymentsProfile", "SetExpressCheckout", responseValues, service.getLastRequest(), service.getLastResponse(), response.Errors, redirectUrl);
        }
    // # CreateRecurringPaymentsProfile API Operation
    // The CreateRecurringPaymentsProfile API operation creates a recurring payments profile.
    // You must invoke the CreateRecurringPaymentsProfile API operation for each profile you want to create. 
    // The API operation creates a profile and an associated billing agreement. 
    // Note: 
    // There is a one-to-one correspondence between billing agreements and recurring payments profiles. 
    // To associate a recurring payments profile with its billing agreement, 
    // you must ensure that the description in the recurring payments profile matches the description of a billing agreement. 
    // For version 54.0 and later, use SetExpressCheckout to initiate creation of a billing agreement.
    public CreateRecurringPaymentsProfileResponseType CreateRecurringPaymentsProfileAPIOperation()
    {
        // Create the CreateRecurringPaymentsProfileResponseType object
        CreateRecurringPaymentsProfileResponseType responseCreateRecurringPaymentsProfileResponseType = new CreateRecurringPaymentsProfileResponseType();

        try
        {
            // Create the CreateRecurringPaymentsProfileReq object
            CreateRecurringPaymentsProfileReq createRecurringPaymentsProfile = new CreateRecurringPaymentsProfileReq();

            // Create the CreateRecurringPaymentsProfileRequestType object
            CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType();

            // You can include up to 10 recurring payments profiles per request. The
            // order of the profile details must match the order of the billing
            // agreement details specified in the SetExpressCheckout request which
            // takes mandatory argument:
            // 
            // * `billing start date` - The date when billing for this profile begins.
            // `Note:
            // The profile may take up to 24 hours for activation.`
            RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails
                = new RecurringPaymentsProfileDetailsType("2013-12-31T13:01:19+00:00");

            // Billing amount for each billing cycle during this payment period.
            // This amount does not include shipping and tax amounts.
            // `Note:
            // All amounts in the CreateRecurringPaymentsProfile request must have
            // the same currency.`
            BasicAmountType billingAmount = new BasicAmountType(CurrencyCodeType.USD, "3.00");

            // Regular payment period for this schedule which takes mandatory
            // params:
            //  
            // * `Billing Period` - Unit for billing during this subscription period. It is one of the
            // following values:
            //  * Day
            //  * Week
            //  * SemiMonth
            //  * Month
            //  * Year
            //  For SemiMonth, billing is done on the 1st and 15th of each month.
            //  `Note:
            //  The combination of BillingPeriod and BillingFrequency cannot exceed
            //  one year.`
            // * `Billing Frequency` - Number of billing periods that make up one billing cycle.
            // The combination of billing frequency and billing period must be less
            // than or equal to one year. For example, if the billing cycle is
            // Month, the maximum value for billing frequency is 12. Similarly, if
            // the billing cycle is Week, the maximum value for billing frequency is
            // 52.
            // `Note:
            // If the billing period is SemiMonth, the billing frequency must be 1.`
            // * `Billing Amount`
            BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(BillingPeriodType.DAY, Convert.ToInt32("5"), billingAmount);

            // Describes the recurring payments schedule, including the regular
            // payment period, whether there is a trial period, and the number of
            // payments that can fail before a profile is suspended which takes
            // mandatory params:
            //  
            // * `Description` - Description of the recurring payment.
            // `Note:
            // You must ensure that this field matches the corresponding billing
            // agreement description included in the SetExpressCheckout request.`
            // * `Payment Period`
            ScheduleDetailsType scheduleDetails = new ScheduleDetailsType("description", paymentPeriod);

            // `CreateRecurringPaymentsProfileRequestDetailsType` which takes
            // mandatory params:
            //      
            // * `Recurring Payments Profile Details`
            // * `Schedule Details`
            CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails
                = new CreateRecurringPaymentsProfileRequestDetailsType(recurringPaymentsProfileDetails, scheduleDetails);

            // Either EC token or a credit card number is required.If you include
            // both token and credit card number, the token is used and credit card number is
            // ignored
            // In case of setting EC token,
            // `createRecurringPaymentsProfileRequestDetails.Token = "EC-5KH01765D1724703R";`
            // A timestamped token, the value of which was returned in the response
            // to the first call to SetExpressCheckout. Call
            // CreateRecurringPaymentsProfile once for each billing
            // agreement included in SetExpressCheckout request and use the same
            // token for each call. Each CreateRecurringPaymentsProfile request
            // creates a single recurring payments profile.
            // `Note:
            // Tokens expire after approximately 3 hours.`

            // Credit card information for recurring payments using direct payments.
            CreditCardDetailsType creditCard = new CreditCardDetailsType();

            // Type of credit card. For UK, only Maestro, MasterCard, Discover, and
            // Visa are allowable. For Canada, only MasterCard and Visa are
            // allowable and Interac debit cards are not supported. It is one of the
            // following values:
            //  
            // * Visa
            // * MasterCard
            // * Discover
            // * Amex
            // * Solo
            // * Switch
            // * Maestro: See note.
            // `Note:
            // If the credit card type is Maestro, you must set currencyId to GBP.
            // In addition, you must specify either StartMonth and StartYear or
            // IssueNumber.`
            creditCard.CreditCardType = CreditCardTypeType.VISA;

            // Credit Card Number
            creditCard.CreditCardNumber = "4442662639546634";

            // Credit Card Expiration Month
            creditCard.ExpMonth = Convert.ToInt32("12");

            // Credit Card Expiration Year
            creditCard.ExpYear = Convert.ToInt32("2016");
            createRecurringPaymentsProfileRequestDetails.CreditCard = creditCard;

            createRecurringPaymentsProfileRequest.CreateRecurringPaymentsProfileRequestDetails
                = createRecurringPaymentsProfileRequestDetails;

            createRecurringPaymentsProfile.CreateRecurringPaymentsProfileRequest = createRecurringPaymentsProfileRequest;

            // # Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();


            // # API call
            // Invoke the CreateRecurringPaymentsProfile method
            responseCreateRecurringPaymentsProfileResponseType
                = service.CreateRecurringPaymentsProfile(createRecurringPaymentsProfile);

            if (responseCreateRecurringPaymentsProfileResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "CreateRecurringPaymentsProfile API Operation - ";
                acknowledgement += responseCreateRecurringPaymentsProfileResponseType.Ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseCreateRecurringPaymentsProfileResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // A unique identifier for future reference to the details of this recurring payment
                    logger.Info("Profile ID : " + responseCreateRecurringPaymentsProfileResponseType.CreateRecurringPaymentsProfileResponseDetails.ProfileID + "\n");
                    Console.WriteLine("Profile ID : " + responseCreateRecurringPaymentsProfileResponseType.CreateRecurringPaymentsProfileResponseDetails.ProfileID + "\n");
                }
                // # Error Values           
                else
                {
                    List<ErrorType> errorMessages = responseCreateRecurringPaymentsProfileResponseType.Errors;
                    foreach (ErrorType error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.LongMessage);
                        Console.WriteLine("API Error Message : " + error.LongMessage + "\n");
                    }
                }
            }
        }
        // # Exception log    
        catch (System.Exception ex)
        {
            // Log the exception message       
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return responseCreateRecurringPaymentsProfileResponseType;
    }