| 1 | package Net::Simplify::Subscription; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Net::Simplify::Subscription - A Simplify Commerce Subscription object | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use Net::Simplify; | ||
| 10 | |||
| 11 | |||
| 12 | $Net::Simplify::public_key = 'YOUR PUBLIC KEY'; | ||
| 13 | $Net::Simplify::private_key = 'YOUR PRIVATE KEY'; | ||
| 14 | |||
| 15 | # Create a new Subscription. | ||
| 16 | my $subscription = Net::Simplify::Subscription->create{ {...}); | ||
| 17 | |||
| 18 | # Retrieve a Subscription given its ID. | ||
| 19 | my $subscription = Net::Simplify::Subscription->find('a7e41'); | ||
| 20 | |||
| 21 | # Update existing Subscription. | ||
| 22 | my $subscription = Net::Simplify::Subscription->find('a7e41'); | ||
| 23 | $subscription->{PROPERTY} = "NEW VALUE"; | ||
| 24 | $subscription->update(); | ||
| 25 | |||
| 26 | # Delete | ||
| 27 | my $subscription = Net::Simplify::Subscription->find('a7e41'); | ||
| 28 | $subscription->delete(); | ||
| 29 | |||
| 30 | # Retrieve a list of objects | ||
| 31 | my $subscriptions = Net::Simplify::Subscription->list({max => 10}); | ||
| 32 | foreach my $v ($subscriptions->list) { | ||
| 33 | # ... | ||
| 34 | } | ||
| 35 | |||
| 36 | =head1 DESCRIPTION | ||
| 37 | |||
| 38 | =head2 METHODS | ||
| 39 | |||
| 40 | =head3 create(%params, $auth) | ||
| 41 | |||
| 42 | Creates a C<Net::Simplify::Subscription> object. The parameters are: | ||
| 43 | |||
| 44 | =over 4 | ||
| 45 | |||
| 46 | =item C<%params> | ||
| 47 | |||
| 48 | Hash map containing initial values for the object. Valid keys are: | ||
| 49 | |||
| 50 | =over 4 | ||
| 51 | |||
| 52 | =item amount | ||
| 53 | |||
| 54 | Amount of the payment in the smallest unit of your currency. Example: 100 = $1.00 | ||
| 55 | |||
| 56 | =item billingCycle | ||
| 57 | |||
| 58 | 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] | ||
| 59 | |||
| 60 | =item billingCycleLimit | ||
| 61 | |||
| 62 | The number of fixed billing cycles for a plan. Only used if the billingCycle parameter is set to FIXED. Example: 4 | ||
| 63 | |||
| 64 | =item coupon | ||
| 65 | |||
| 66 | Coupon ID associated with the subscription | ||
| 67 | |||
| 68 | =item currency | ||
| 69 | |||
| 70 | Currency code (ISO-4217). Must match the currency associated with your account. | ||
| 71 | |||
| 72 | =item currentPeriodEnd | ||
| 73 | |||
| 74 | End date of subscription's current period | ||
| 75 | |||
| 76 | =item currentPeriodStart | ||
| 77 | |||
| 78 | Start date of subscription's current period | ||
| 79 | |||
| 80 | =item customer | ||
| 81 | |||
| 82 | Customer that is enrolling in the subscription. | ||
| 83 | |||
| 84 | =item frequency | ||
| 85 | |||
| 86 | Frequency of payment for the plan. Used in conjunction with frequencyPeriod. Valid values are "DAILY", "WEEKLY", "MONTHLY" and "YEARLY". | ||
| 87 | |||
| 88 | =item frequencyPeriod | ||
| 89 | |||
| 90 | 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. | ||
| 91 | |||
| 92 | =item name | ||
| 93 | |||
| 94 | Name describing subscription [max length: 50] | ||
| 95 | |||
| 96 | =item plan | ||
| 97 | |||
| 98 | The ID of the plan that should be used for the subscription. | ||
| 99 | |||
| 100 | =item quantity | ||
| 101 | |||
| 102 | Quantity of the plan for the subscription. [min value: 1] | ||
| 103 | |||
| 104 | =item renewalReminderLeadDays | ||
| 105 | |||
| 106 | 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. | ||
| 107 | |||
| 108 | =item source | ||
| 109 | |||
| 110 | Source of where subscription was created | ||
| 111 | |||
| 112 | |||
| 113 | =back | ||
| 114 | |||
| 115 | =item C<$auth> | ||
| 116 | |||
| 117 | Authentication object for accessing the API. If no value is passed the global keys | ||
| 118 | C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used. | ||
| 119 | |||
| 120 | =back | ||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | |||
| 125 | =head3 delete() | ||
| 126 | |||
| 127 | Deletes the C<Net::Simplify::Subscription> object. Authentication is done using the same credentials used when the AccessToken was created. | ||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | =head3 list(%criteria, $auth) | ||
| 132 | |||
| 133 | Retrieve a list of C<Net::Simplify::Subscription> objects. The parameters are: | ||
| 134 | |||
| 135 | =over 4 | ||
| 136 | |||
| 137 | =item C<%criteria> | ||
| 138 | |||
| 139 | Hash map representing the criteria to limit the results of the list operation. Valid keys are: | ||
| 140 | |||
| 141 | =over 4 | ||
| 142 | |||
| 143 | =item C<filter> | ||
| 144 | |||
| 145 | <table class="filter_list"><tr><td>filter.customer</td><td>Filter by the Id of the customer with the subscription</td></tr><tr><td>filter.plan</td><td>Filter by the Id of the plan linked to the subscription</td></tr><tr><td>filter.dateCreatedMin<sup>*</sup></td><td>Filter by the minimum created date you are searching for - Date in UTC millis</td></tr><tr><td>filter.dateCreatedMax<sup>*</sup></td><td>Filter by the maximum created date you are searching for - Date in UTC millis</td></tr><tr><td>filter.q</td><td>You can use this to filter by the Id, the name or the amount of the subscription</td></tr></table><br><sup>*</sup>Use dateCreatedMin with dateCreatedMax in the same filter if you want to search between two created dates | ||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | =item C<max> | ||
| 150 | |||
| 151 | Allows up to a max of 50 list items to return. [min value: 0, max value: 50, default: 20] | ||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | =item C<offset> | ||
| 156 | |||
| 157 | Used in paging of the list. This is the start offset of the page. [min value: 0, default: 0] | ||
| 158 | |||
| 159 | |||
| 160 | |||
| 161 | =item C<sorting> | ||
| 162 | |||
| 163 | Allows for ascending or descending sorting of the list. | ||
| 164 | The value maps properties to the sort direction (either C<asc> for ascending or C<desc> for descending). Sortable properties are: | ||
| 165 | |||
| 166 | =over 4 | ||
| 167 | |||
| 168 | =item C<dateCreated> | ||
| 169 | |||
| 170 | =item C<id> | ||
| 171 | |||
| 172 | =item C<plan> | ||
| 173 | |||
| 174 | |||
| 175 | =back | ||
| 176 | |||
| 177 | |||
| 178 | |||
| 179 | |||
| 180 | =back | ||
| 181 | |||
| 182 | =back | ||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | =head3 find($id, $auth) | ||
| 187 | |||
| 188 | Retrieve a C<Net::Simplify::Subscription> object from the API. Parameters are: | ||
| 189 | |||
| 190 | =over 4 | ||
| 191 | |||
| 192 | =item C<$id> | ||
| 193 | |||
| 194 | Identifier of the object to retrieve. | ||
| 195 | |||
| 196 | =item C<$auth> | ||
| 197 | |||
| 198 | Authentication object for accessing the API. If no value is passed the global keys | ||
| 199 | C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used. | ||
| 200 | |||
| 201 | =back | ||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | |||
| 206 | =head3 update() | ||
| 207 | |||
| 208 | Update C<Net::Simplify::Subscription> object. | ||
| 209 | The properties that can be updated are: | ||
| 210 | |||
| 211 | =over 4 | ||
| 212 | |||
| 213 | |||
| 214 | =item C<amount> | ||
| 215 | |||
| 216 | Amount of the payment in the smallest unit of your currency. Example: 100 = $1.00 | ||
| 217 | |||
| 218 | =item C<billingCycle> | ||
| 219 | |||
| 220 | 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] | ||
| 221 | |||
| 222 | =item C<billingCycleLimit> | ||
| 223 | |||
| 224 | The number of fixed billing cycles for a plan. Only used if the billingCycle parameter is set to FIXED. Example: 4 | ||
| 225 | |||
| 226 | =item C<coupon> | ||
| 227 | |||
| 228 | Coupon being assigned to this subscription | ||
| 229 | |||
| 230 | =item C<currency> | ||
| 231 | |||
| 232 | Currency code (ISO-4217). Must match the currency associated with your account. | ||
| 233 | |||
| 234 | =item C<currentPeriodEnd> | ||
| 235 | |||
| 236 | End date of subscription's current period | ||
| 237 | |||
| 238 | =item C<currentPeriodStart> | ||
| 239 | |||
| 240 | Start date of subscription's current period | ||
| 241 | |||
| 242 | =item C<frequency> | ||
| 243 | |||
| 244 | Frequency of payment for the plan. Used in conjunction with frequencyPeriod. Valid values are "DAILY", "WEEKLY", "MONTHLY" and "YEARLY". | ||
| 245 | |||
| 246 | =item C<frequencyPeriod> | ||
| 247 | |||
| 248 | 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] | ||
| 249 | |||
| 250 | |||
| 251 | =item C<name> | ||
| 252 | |||
| 253 | Name describing subscription | ||
| 254 | |||
| 255 | =item C<plan> | ||
| 256 | |||
| 257 | Plan that should be used for the subscription. | ||
| 258 | |||
| 259 | =item C<prorate> | ||
| 260 | |||
| 261 | Whether to prorate existing subscription. [default: true] (B<required>) | ||
| 262 | |||
| 263 | =item C<quantity> | ||
| 264 | |||
| 265 | Quantity of the plan for the subscription. [min value: 1] | ||
| 266 | |||
| 267 | =item C<renewalReminderLeadDays> | ||
| 268 | |||
| 269 | 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. | ||
| 270 | |||
| 271 | Authentication is done using the same credentials used when the AccessToken was created. | ||
| 272 | |||
| 273 | =back | ||
| 274 | |||
| 275 | |||
| 276 | |||
| 277 | |||
| 278 | =head1 SEE ALSO | ||
| 279 | |||
| 280 | L<Net::Simplify>, | ||
| 281 | L<Net::Simplify::Domain>, | ||
| 282 | L<Net::Simplify::DomainList>, | ||
| 283 | L<Net::Simplify::Authentication>, | ||
| 284 | L<Net::Simplify::ApiException>, | ||
| 285 | L<http://www.simplify.com> | ||
| 286 | |||
| 287 | =head1 VERSION | ||
| 288 | |||
| 289 | 1.6.0 | ||
| 290 | |||
| 291 | =head1 LICENSE | ||
| 292 | |||
| 293 | Copyright (c) 2013 - 2022 MasterCard International Incorporated | ||
| 294 | All rights reserved. | ||
| 295 | |||
| 296 | Redistribution and use in source and binary forms, with or without modification, are | ||
| 297 | permitted provided that the following conditions are met: | ||
| 298 | |||
| 299 | Redistributions of source code must retain the above copyright notice, this list of | ||
| 300 | conditions and the following disclaimer. | ||
| 301 | Redistributions in binary form must reproduce the above copyright notice, this list of | ||
| 302 | conditions and the following disclaimer in the documentation and/or other materials | ||
| 303 | provided with the distribution. | ||
| 304 | Neither the name of the MasterCard International Incorporated nor the names of its | ||
| 305 | contributors may be used to endorse or promote products derived from this software | ||
| 306 | without specific prior written permission. | ||
| 307 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| 308 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 309 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| 310 | SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 311 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| 312 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 313 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| 314 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
| 315 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 316 | SUCH DAMAGE. | ||
| 317 | |||
| 318 | =head1 SEE ALSO | ||
| 319 | |||
| 320 | =cut | ||
| 321 | |||
| 322 | use 5.006; | ||
| 323 | use strict; | ||
| 324 | use warnings FATAL => 'all'; | ||
| 325 | |||
| 326 | use Net::Simplify::Domain; | ||
| 327 | use Net::Simplify::DomainList; | ||
| 328 | |||
| 329 | our @ISA = qw(Net::Simplify::Domain); | ||
| 330 | |||
| 331 | sub create { | ||
| 332 | |||
| 333 | my ($class, $params, $auth) = @_; | ||
| 334 | |||
| 335 | $auth = Net::Simplify::SimplifyApi->get_authentication($auth); | ||
| 336 | my $result = Net::Simplify::SimplifyApi->send_api_request("subscription", 'create', $params, $auth); | ||
| 337 | |||
| 338 | $class->SUPER::new($result, $auth); | ||
| 339 | } | ||
| 340 | |||
| 341 | sub delete { | ||
| 342 | |||
| 343 | my ($self) = @_; | ||
| 344 | |||
| 345 | my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication}); | ||
| 346 | |||
| 347 | my $id = $self->{id}; | ||
| 348 | $self->merge(Net::Simplify::SimplifyApi->send_api_request("subscription", 'delete', {id => $id}, $auth)); | ||
| 349 | } | ||
| 350 | |||
| 351 | sub list { | ||
| 352 | my ($class, $criteria, $auth) = @_; | ||
| 353 | |||
| 354 | $auth = Net::Simplify::SimplifyApi->get_authentication($auth); | ||
| 355 | my $result = Net::Simplify::SimplifyApi->send_api_request("subscription", 'list', $criteria, $auth); | ||
| 356 | |||
| 357 | Net::Simplify::DomainList->new($result, $class, $auth); | ||
| 358 | } | ||
| 359 | |||
| 360 | sub find { | ||
| 361 | my ($class, $id, $auth) = @_; | ||
| 362 | |||
| 363 | $auth = Net::Simplify::SimplifyApi->get_authentication($auth); | ||
| 364 | my $result = Net::Simplify::SimplifyApi->send_api_request("subscription", 'find', { id => $id }, $auth); | ||
| 365 | |||
| 366 | $class->SUPER::new($result, $auth); | ||
| 367 | } | ||
| 368 | |||
| 369 | sub update { | ||
| 370 | |||
| 371 | my ($self) = @_; | ||
| 372 | |||
| 373 | my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication}); | ||
| 374 | my $params = { %$self }; | ||
| 375 | delete $params->{_authentication}; | ||
| 376 | |||
| 377 | $self->merge(Net::Simplify::SimplifyApi->send_api_request("subscription", 'update', $params, $auth)); | ||
| 378 | } | ||
| 379 | |||
| 380 | |||
| 381 | 1; |