| 1 | package plenigo::CheckoutHelper; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | plenigo::CheckoutHelper - A utility class offering support for checkout functionality. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use plenigo::CheckoutHelper; | ||
| 10 | |||
| 11 | my $use_stage = 0; # set if stage system should be used | ||
| 12 | my $configuration = plenigo::Configuration->new(access_token => 'ACCESS_TOKEN', use_stage => $use_stage); | ||
| 13 | |||
| 14 | my $offer = plenigo::Offer->createPlenigoOffer('CUSTOMER_ID', 'CUSTOMER_IP_ADDRESS', ((plenigoOfferId => 'OFFER_ID1'))); | ||
| 15 | my $checkout_helper = plenigo::CheckoutHelper->new(configuration => $configuration); | ||
| 16 | my $purchase_id = $checkout_helper->getPurchaseId($offer); | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | plenigo::CheckoutHelper provides functionality to prepare a plenigo checkout. | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | use Moo; | ||
| 25 | use Carp qw(confess); | ||
| 26 | use Crypt::JWT qw(encode_jwt); | ||
| 27 | use Data::UUID; | ||
| 28 | |||
| 29 | our $VERSION = '3.0002'; | ||
| 30 | |||
| 31 | has configuration => ( | ||
| 32 | is => 'ro', | ||
| 33 | required => 1 | ||
| 34 | ); | ||
| 35 | |||
| 36 | =head1 METHODS | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | =head2 getPurchaseId($offer) | ||
| 41 | |||
| 42 | Get purchase id necessary for plenigo checkout. | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | sub getPurchaseId { | ||
| 47 | my ($self, $offer) = @_; | ||
| 48 | |||
| 49 | my $rest_client = plenigo::RestClient->new(configuration => $self->configuration); | ||
| 50 | my %result = $rest_client->post('checkout/preparePurchase', {}, $offer); | ||
| 51 | |||
| 52 | if ($result{'response_code'} == 404) { | ||
| 53 | plenigo::Ex->throw({ code => 404, message => 'There is no customer for the customer id passed.' }); | ||
| 54 | } | ||
| 55 | |||
| 56 | return %{$result{'response_content'}}; | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; |