Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.95 KB | None | 0 0
  1. using PayPal.PayPalAPIInterfaceService;
  2. using PayPal.PayPalAPIInterfaceService.Model;
  3.  
  4. // # CreateRecurringPaymentsProfile API Operation
  5. // The CreateRecurringPaymentsProfile API operation creates a recurring payments profile.
  6. // You must invoke the CreateRecurringPaymentsProfile API operation for each profile you want to create.
  7. // The API operation creates a profile and an associated billing agreement.
  8. // Note:
  9. // There is a one-to-one correspondence between billing agreements and recurring payments profiles.
  10. // To associate a recurring payments profile with its billing agreement,
  11. // you must ensure that the description in the recurring payments profile matches the description of a billing agreement.
  12. // For version 54.0 and later, use SetExpressCheckout to initiate creation of a billing agreement.
  13. public PayPalSandbox.CreateRecurringPaymentsProfileResponseType CreateRecurringPaymentsProfileAPIOperation()
  14. {
  15. // Create the CreateRecurringPaymentsProfileResponseType object
  16. PayPalSandbox.CreateRecurringPaymentsProfileResponseType responseCreateRecurringPaymentsProfileResponseType =
  17. new PayPalSandbox.CreateRecurringPaymentsProfileResponseType();
  18.  
  19. try
  20. {
  21. // Where do I add this to be able to complete the call?
  22. PayPalSandbox.APICredentialsType credentials = new PayPalSandbox.APICredentialsType();
  23. credentials.Username = "username";
  24. credentials.Password = "password";
  25. credentials.Signature = "signature";
  26.  
  27. // Create the CreateRecurringPaymentsProfileReq object
  28. PayPalSandbox.CreateRecurringPaymentsProfileReq createRecurringPaymentsProfile =
  29. new PayPalSandbox.CreateRecurringPaymentsProfileReq();
  30.  
  31. // Create the CreateRecurringPaymentsProfileRequestType object
  32. PayPalSandbox.CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest =
  33. new PayPalSandbox.CreateRecurringPaymentsProfileRequestType();
  34.  
  35. // You can include up to 10 recurring payments profiles per request. The
  36. // order of the profile details must match the order of the billing
  37. // agreement details specified in the SetExpressCheckout request which
  38. // takes mandatory argument:
  39. //
  40. // * `billing start date` - The date when billing for this profile begins.
  41. // `Note:
  42. // The profile may take up to 24 hours for activation.`
  43. PayPalSandbox.RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails
  44. = new PayPalSandbox.RecurringPaymentsProfileDetailsType();
  45. recurringPaymentsProfileDetails.BillingStartDate = DateTime.Parse("2013-12-31T13:01:19+00:00");
  46.  
  47. // Billing amount for each billing cycle during this payment period.
  48. // This amount does not include shipping and tax amounts.
  49. // `Note:
  50. // All amounts in the CreateRecurringPaymentsProfile request must have
  51. // the same currency.`
  52. PayPalSandbox.BasicAmountType billingAmount = new PayPalSandbox.BasicAmountType();
  53. billingAmount.currencyID = PayPalSandbox.CurrencyCodeType.CAD;
  54. billingAmount.Value = txtAmount.Text;
  55.  
  56.  
  57. // Regular payment period for this schedule which takes mandatory
  58. // params:
  59. //
  60. // * `Billing Period` - Unit for billing during this subscription period. It is one of the
  61. // following values:
  62. // * Day
  63. // * Week
  64. // * SemiMonth
  65. // * Month
  66. // * Year
  67. // For SemiMonth, billing is done on the 1st and 15th of each month.
  68. // `Note:
  69. // The combination of BillingPeriod and BillingFrequency cannot exceed
  70. // one year.`
  71. // * `Billing Frequency` - Number of billing periods that make up one billing cycle.
  72. // The combination of billing frequency and billing period must be less
  73. // than or equal to one year. For example, if the billing cycle is
  74. // Month, the maximum value for billing frequency is 12. Similarly, if
  75. // the billing cycle is Week, the maximum value for billing frequency is
  76. // 52.
  77. // `Note:
  78. // If the billing period is SemiMonth, the billing frequency must be 1.`
  79. // * `Billing Amount`
  80. PayPalSandbox.BillingPeriodDetailsType paymentPeriod =
  81. new PayPalSandbox.BillingPeriodDetailsType();
  82. paymentPeriod.BillingPeriod = PayPalSandbox.BillingPeriodType.Month;
  83. paymentPeriod.BillingFrequency = 12;
  84. paymentPeriod.Amount = billingAmount;
  85.  
  86. // Describes the recurring payments schedule, including the regular
  87. // payment period, whether there is a trial period, and the number of
  88. // payments that can fail before a profile is suspended which takes
  89. // mandatory params:
  90. //
  91. // * `Description` - Description of the recurring payment.
  92. // `Note:
  93. // You must ensure that this field matches the corresponding billing
  94. // agreement description included in the SetExpressCheckout request.`
  95. // * `Payment Period`
  96. PayPalSandbox.ScheduleDetailsType scheduleDetails =
  97. new PayPalSandbox.ScheduleDetailsType();
  98. scheduleDetails.Description = rblDonationType.SelectedItem.Text;
  99. scheduleDetails.PaymentPeriod = paymentPeriod;
  100.  
  101. // `CreateRecurringPaymentsProfileRequestDetailsType` which takes
  102. // mandatory params:
  103. //
  104. // * `Recurring Payments Profile Details`
  105. // * `Schedule Details`
  106. PayPalSandbox.CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails
  107. = new PayPalSandbox.CreateRecurringPaymentsProfileRequestDetailsType();
  108. createRecurringPaymentsProfileRequestDetails.RecurringPaymentsProfileDetails = recurringPaymentsProfileDetails;
  109. createRecurringPaymentsProfileRequestDetails.ScheduleDetails = scheduleDetails;
  110.  
  111. // Either EC token or a credit card number is required.If you include
  112. // both token and credit card number, the token is used and credit card number is
  113. // ignored
  114. // In case of setting EC token,
  115. // `createRecurringPaymentsProfileRequestDetails.Token = "EC-5KH01765D1724703R";`
  116. // A timestamped token, the value of which was returned in the response
  117. // to the first call to SetExpressCheckout. Call
  118. // CreateRecurringPaymentsProfile once for each billing
  119. // agreement included in SetExpressCheckout request and use the same
  120. // token for each call. Each CreateRecurringPaymentsProfile request
  121. // creates a single recurring payments profile.
  122. // `Note:
  123. // Tokens expire after approximately 3 hours.`
  124.  
  125. // Credit card information for recurring payments using direct payments.
  126. //PayPalSandbox.CreditCardDetailsType creditCard = new PayPalSandbox.CreditCardDetailsType();
  127.  
  128. // Type of credit card. For UK, only Maestro, MasterCard, Discover, and
  129. // Visa are allowable. For Canada, only MasterCard and Visa are
  130. // allowable and Interac debit cards are not supported. It is one of the
  131. // following values:
  132. //
  133. // * Visa
  134. // * MasterCard
  135. // * Discover
  136. // * Amex
  137. // * Solo
  138. // * Switch
  139. // * Maestro: See note.
  140. // `Note:
  141. // If the credit card type is Maestro, you must set currencyId to GBP.
  142. // In addition, you must specify either StartMonth and StartYear or
  143. // IssueNumber.`
  144. //creditCard.CreditCardType = CreditCardTypeType.VISA;
  145.  
  146. // Credit Card Number
  147. //creditCard.CreditCardNumber = "4442662639546634";
  148.  
  149. // Credit Card Expiration Month
  150. //creditCard.ExpMonth = Convert.ToInt32("12");
  151.  
  152. // Credit Card Expiration Year
  153. //creditCard.ExpYear = Convert.ToInt32("2016");
  154. //createRecurringPaymentsProfileRequestDetails.CreditCard = creditCard;
  155.  
  156. createRecurringPaymentsProfileRequest.CreateRecurringPaymentsProfileRequestDetails
  157. = createRecurringPaymentsProfileRequestDetails;
  158.  
  159. createRecurringPaymentsProfile.CreateRecurringPaymentsProfileRequest = createRecurringPaymentsProfileRequest;
  160.  
  161. // # Create the service wrapper object to make the API call
  162. PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
  163.  
  164.  
  165.  
  166.  
  167. // # API call
  168. // Invoke the CreateRecurringPaymentsProfile method
  169. responseCreateRecurringPaymentsProfileResponseType
  170. = service.CreateRecurringPaymentsProfile(createRecurringPaymentsProfile);
  171.  
  172. if (responseCreateRecurringPaymentsProfileResponseType != null)
  173. {
  174. // Response envelope acknowledgement
  175. string acknowledgement = "CreateRecurringPaymentsProfile API Operation - ";
  176. acknowledgement += responseCreateRecurringPaymentsProfileResponseType.Ack.ToString();
  177. //logger.Info(acknowledgement + "n");
  178. Console.WriteLine(acknowledgement + "n");
  179.  
  180. // # Success values
  181. if (responseCreateRecurringPaymentsProfileResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
  182. {
  183. // A unique identifier for future reference to the details of this recurring payment
  184. //logger.Info("Profile ID : " + responseCreateRecurringPaymentsProfileResponseType.CreateRecurringPaymentsProfileResponseDetails.ProfileID + "n");
  185. Console.WriteLine("Profile ID : " + responseCreateRecurringPaymentsProfileResponseType.CreateRecurringPaymentsProfileResponseDetails.ProfileID + "n");
  186. }
  187. // # Error Values
  188. else
  189. {
  190. List<PayPalSandbox.ErrorType> errorMessages = responseCreateRecurringPaymentsProfileResponseType.Errors.ToList< PayPalSandbox.ErrorType>();
  191. foreach (PayPalSandbox.ErrorType error in errorMessages)
  192. {
  193. //logger.Debug("API Error Message : " + error.LongMessage);
  194. Console.WriteLine("API Error Message : " + error.LongMessage + "n");
  195. }
  196. }
  197. }
  198. }
  199. // # Exception log
  200. catch (System.Exception ex)
  201. {
  202. // Log the exception message
  203. //logger.Debug("Error Message : " + ex.Message);
  204. Console.WriteLine("Error Message : " + ex.Message);
  205. }
  206. return responseCreateRecurringPaymentsProfileResponseType;
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement