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