PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/woocommerce/includes/gateways/simplify-commerce/includes/Simplify/Subscription.php

https://gitlab.com/webkod3r/tripolis
PHP | 160 lines | 42 code | 27 blank | 91 comment | 0 complexity | 2355d3d0338a46cb383c59c79e271ade MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (c) 2013 - 2015 MasterCard International Incorporated
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification, are
  7. * permitted provided that the following conditions are met:
  8. *
  9. * Redistributions of source code must retain the above copyright notice, this list of
  10. * conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this list of
  12. * conditions and the following disclaimer in the documentation and/or other materials
  13. * provided with the distribution.
  14. * Neither the name of the MasterCard International Incorporated nor the names of its
  15. * contributors may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  20. * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  22. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  24. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  25. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. class Simplify_Subscription extends Simplify_Object {
  29. /**
  30. * Creates an Simplify_Subscription object
  31. * @param array $hash a map of parameters; valid keys are:<dl style="padding-left:10px;">
  32. * <dt><tt>amount</tt></dt> <dd>Amount of the payment in the smallest unit of your currency. Example: 100 = $1.00USD </dd>
  33. * <dt><tt>billingCycle</tt></dt> <dd>How the plan is billed to the customer. Values must be AUTO (indefinitely until the customer cancels) or FIXED (a fixed number of billing cycles). [default: AUTO] </dd>
  34. * <dt><tt>billingCycleLimit</tt></dt> <dd>The number of fixed billing cycles for a plan. Only used if the billingCycle parameter is set to FIXED. Example: 4 </dd>
  35. * <dt><tt>coupon</tt></dt> <dd>Coupon ID associated with the subscription </dd>
  36. * <dt><tt>currency</tt></dt> <dd>Currency code (ISO-4217). Must match the currency associated with your account. [default: USD] </dd>
  37. * <dt><tt>customer</tt></dt> <dd>Customer that is enrolling in the subscription. </dd>
  38. * <dt><tt>frequency</tt></dt> <dd>Frequency of payment for the plan. Used in conjunction with frequencyPeriod. Valid values are "DAILY", "WEEKLY", "MONTHLY" and "YEARLY". </dd>
  39. * <dt><tt>frequencyPeriod</tt></dt> <dd>Period of frequency of payment for the plan. Example: if the frequency is weekly, and periodFrequency is 2, then the subscription is billed bi-weekly. </dd>
  40. * <dt><tt>name</tt></dt> <dd>Name describing subscription </dd>
  41. * <dt><tt>plan</tt></dt> <dd>The ID of the plan that should be used for the subscription. </dd>
  42. * <dt><tt>quantity</tt></dt> <dd>Quantity of the plan for the subscription. [min value: 1] </dd>
  43. * <dt><tt>renewalReminderLeadDays</tt></dt> <dd>If set, how many days before the next billing cycle that a renewal reminder is sent to the customer. If null, then no emails are sent. Minimum value is 7 if set. </dd></dl>
  44. * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. <i>For backwards compatibility the public and private keys may be passed instead of the authentication object.<i/>
  45. * @return Subscription a Subscription object.
  46. */
  47. static public function createSubscription($hash, $authentication = null) {
  48. $args = func_get_args();
  49. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 2);
  50. $instance = new Simplify_Subscription();
  51. $instance->setAll($hash);
  52. $object = Simplify_PaymentsApi::createObject($instance, $authentication);
  53. return $object;
  54. }
  55. /**
  56. * Deletes an Simplify_Subscription object.
  57. *
  58. * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. <i>For backwards compatibility the public and private keys may be passed instead of the authentication object.</i>
  59. */
  60. public function deleteSubscription($authentication = null) {
  61. $args = func_get_args();
  62. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 1);
  63. $obj = Simplify_PaymentsApi::deleteObject($this, $authentication);
  64. $this->properties = null;
  65. return true;
  66. }
  67. /**
  68. * Retrieve Simplify_Subscription objects.
  69. * @param array criteria a map of parameters; valid keys are:<dl style="padding-left:10px;">
  70. * <dt><tt>filter</tt></dt> <dd>Filters to apply to the list. </dd>
  71. * <dt><tt>max</tt></dt> <dd>Allows up to a max of 50 list items to return. [min value: 0, max value: 50, default: 20] </dd>
  72. * <dt><tt>offset</tt></dt> <dd>Used in paging of the list. This is the start offset of the page. [min value: 0, default: 0] </dd>
  73. * <dt><tt>sorting</tt></dt> <dd>Allows for ascending or descending sorting of the list. The value maps properties to the sort direction (either <tt>asc</tt> for ascending or <tt>desc</tt> for descending). Sortable properties are: <tt> id</tt><tt> plan</tt>.</dd></dl>
  74. * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. <i>For backwards compatibility the public and private keys may be passed instead of the authentication object.</i>
  75. * @return ResourceList a ResourceList object that holds the list of Subscription objects and the total
  76. * number of Subscription objects available for the given criteria.
  77. * @see ResourceList
  78. */
  79. static public function listSubscription($criteria = null, $authentication = null) {
  80. $args = func_get_args();
  81. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 2);
  82. $val = new Simplify_Subscription();
  83. $list = Simplify_PaymentsApi::listObject($val, $criteria, $authentication);
  84. return $list;
  85. }
  86. /**
  87. * Retrieve a Simplify_Subscription object from the API
  88. *
  89. * @param string id the id of the Subscription object to retrieve
  90. * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. <i>For backwards compatibility the public and private keys may be passed instead of the authentication object.</i>
  91. * @return Subscription a Subscription object
  92. */
  93. static public function findSubscription($id, $authentication = null) {
  94. $args = func_get_args();
  95. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 2);
  96. $val = new Simplify_Subscription();
  97. $val->id = $id;
  98. $obj = Simplify_PaymentsApi::findObject($val, $authentication);
  99. return $obj;
  100. }
  101. /**
  102. * Updates an Simplify_Subscription object.
  103. *
  104. * The properties that can be updated:
  105. * <dl style="padding-left:10px;">
  106. * <dt><tt>amount</tt></dt> <dd>Amount of the payment in the smallest unit of your currency. Example: 100 = $1.00USD </dd>
  107. * <dt><tt>billingCycle</tt></dt> <dd>How the plan is billed to the customer. Values must be AUTO (indefinitely until the customer cancels) or FIXED (a fixed number of billing cycles). [default: AUTO] </dd>
  108. * <dt><tt>billingCycleLimit</tt></dt> <dd>The number of fixed billing cycles for a plan. Only used if the billingCycle parameter is set to FIXED. Example: 4 </dd>
  109. * <dt><tt>coupon</tt></dt> <dd>Coupon being assigned to this subscription </dd>
  110. * <dt><tt>currency</tt></dt> <dd>Currency code (ISO-4217). Must match the currency associated with your account. [default: USD] </dd>
  111. * <dt><tt>frequency</tt></dt> <dd>Frequency of payment for the plan. Used in conjunction with frequencyPeriod. Valid values are "DAILY", "WEEKLY", "MONTHLY" and "YEARLY". </dd>
  112. * <dt><tt>frequencyPeriod</tt></dt> <dd>Period of frequency of payment for the plan. Example: if the frequency is weekly, and periodFrequency is 2, then the subscription is billed bi-weekly. [min value: 1] </dd>
  113. * <dt><tt>name</tt></dt> <dd>Name describing subscription </dd>
  114. * <dt><tt>plan</tt></dt> <dd>Plan that should be used for the subscription. </dd>
  115. * <dt><tt>prorate</tt></dt> <dd>Whether to prorate existing subscription. [default: true] <strong>required </strong></dd>
  116. * <dt><tt>quantity</tt></dt> <dd>Quantity of the plan for the subscription. [min value: 1] </dd>
  117. * <dt><tt>renewalReminderLeadDays</tt></dt> <dd>If set, how many days before the next billing cycle that a renewal reminder is sent to the customer. If null or 0, no emails are sent. Minimum value is 7 if set. </dd></dl>
  118. * @param $authentication - information used for the API call. If no value is passed the global keys Simplify::public_key and Simplify::private_key are used. <i>For backwards compatibility the public and private keys may be passed instead of the authentication object.</i>
  119. * @return Subscription a Subscription object.
  120. */
  121. public function updateSubscription($authentication = null) {
  122. $args = func_get_args();
  123. $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 1);
  124. $object = Simplify_PaymentsApi::updateObject($this, $authentication);
  125. return $object;
  126. }
  127. /**
  128. * @ignore
  129. */
  130. public function getClazz() {
  131. return "Subscription";
  132. }
  133. }