| 1 | package plenigo::PurchasesManager; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | plenigo::PurchasesManager - A utility class to offer purchase information. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use plenigo::PurchasesManager; | ||
| 10 | |||
| 11 | # Prepare configuration | ||
| 12 | |||
| 13 | my $use_stage = 0; # set if stage system should be used | ||
| 14 | my $configuration = plenigo::Configuration->new(access_token => 'ACCESS_TOKEN', use_stage => $use_stage); | ||
| 15 | |||
| 16 | # Instantiate purchases manager | ||
| 17 | |||
| 18 | my $purchases_manager = plenigo::PurchasesManager->new(configuration => $configuration); | ||
| 19 | |||
| 20 | # Get all subscriptions of a customer | ||
| 21 | |||
| 22 | my %subscriptions = $purchases_manager->getCustomerSubscriptions('CUSTOMER_ID'); | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | plenigo::CustomerPurchasesManager provides functionality to offer purchase information. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | use Moo; | ||
| 31 | use Carp qw(confess); | ||
| 32 | use plenigo::Ex; | ||
| 33 | use plenigo::RestClient; | ||
| 34 | |||
| 35 | our $VERSION = '3.0002'; | ||
| 36 | |||
| 37 | has configuration => ( | ||
| 38 | is => 'ro', | ||
| 39 | required => 1 | ||
| 40 | ); | ||
| 41 | |||
| 42 | =head2 getCustomerSubscriptions($customer_id) | ||
| 43 | |||
| 44 | Get all subscriptions that were purchased by a customer. | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | sub getCustomerSubscriptions { | ||
| 49 | my ($self, $customer_id) = @_; | ||
| 50 | |||
| 51 | my $rest_client = plenigo::RestClient->new(configuration => $self->configuration); | ||
| 52 | my %result = $rest_client->get('customers/' . $customer_id . "/subscriptions"); | ||
| 53 | |||
| 54 | if ($result{'response_code'} == 404) { | ||
| 55 | plenigo::Ex->throw({ code => 409, message => 'No customer can be found for the given customer id.' }); | ||
| 56 | } | ||
| 57 | else { | ||
| 58 | return %{$result{'response_content'}}; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; |