| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Flotum; | 
| 2 | 4 |  |  | 4 |  | 2756 | use strict; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 103 |  | 
| 3 | 4 |  |  | 4 |  | 80 | use 5.008_005; | 
|  | 4 |  |  |  |  | 13 |  | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.11'; | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 19 | use warnings; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 92 |  | 
| 7 | 4 |  |  | 4 |  | 1696 | use utf8; | 
|  | 4 |  |  |  |  | 41 |  | 
|  | 4 |  |  |  |  | 19 |  | 
| 8 | 4 |  |  | 4 |  | 120 | use Carp qw/croak confess/; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 214 |  | 
| 9 | 4 |  |  | 4 |  | 1977 | use Moo; | 
|  | 4 |  |  |  |  | 42498 |  | 
|  | 4 |  |  |  |  | 21 |  | 
| 10 | 4 |  |  | 4 |  | 7165 | use namespace::clean; | 
|  | 4 |  |  |  |  | 42063 |  | 
|  | 4 |  |  |  |  | 25 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 4 |  |  | 4 |  | 2918 | use Net::Flotum::API::Charge; | 
|  | 4 |  |  |  |  | 14 |  | 
|  | 4 |  |  |  |  | 131 |  | 
| 13 | 4 |  |  | 4 |  | 1739 | use Net::Flotum::API::Customer; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 144 |  | 
| 14 | 4 |  |  | 4 |  | 1638 | use Net::Flotum::API::RequestHandler; | 
|  | 4 |  |  |  |  | 13 |  | 
|  | 4 |  |  |  |  | 124 |  | 
| 15 | 4 |  |  | 4 |  | 1872 | use Log::Any; | 
|  | 4 |  |  |  |  | 31078 |  | 
|  | 4 |  |  |  |  | 18 |  | 
| 16 | 4 |  |  | 4 |  | 2095 | use Net::Flotum::Object::Customer; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 3387 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has 'logger'    => ( is => 'ro', builder => '_build_logger',    lazy => 1 ); | 
| 19 |  |  |  |  |  |  | has 'requester' => ( is => 'ro', builder => '_build_requester', lazy => 1 ); | 
| 20 |  |  |  |  |  |  | has 'merchant_api_key' => ( is => 'rw', required => 1 ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | has 'customer_api' => ( is => 'ro', builder => '_build_customer_api', lazy => 1 ); | 
| 23 |  |  |  |  |  |  | has 'charge_api'   => ( is => 'ro', builder => '_build_charge_api',   lazy => 1 ); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub _build_requester { | 
| 26 | 3 |  |  | 3 |  | 41 | Net::Flotum::API::RequestHandler->new; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub _build_logger { | 
| 30 | 3 |  |  | 3 |  | 44 | Log::Any->get_logger; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub _build_customer_api { | 
| 34 | 3 |  |  | 3 |  | 29 | my ($self) = @_; | 
| 35 | 3 |  |  |  |  | 25 | Net::Flotum::API::Customer->new( flotum => $self, ); | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub _build_charge_api { | 
| 39 | 1 |  |  | 1 |  | 12 | my ($self) = @_; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 1 |  |  |  |  | 13 | Net::Flotum::API::Charge->new( flotum => $self ); | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub load_customer { | 
| 45 | 4 |  |  | 4 | 0 | 2648 | my ( $self, %opts ) = @_; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 4 | 50 | 66 |  |  | 22 | my $lazy = 1 if exists $opts{lazy} && $opts{lazy}; | 
| 48 | 4 |  |  |  |  | 8 | my $cus; | 
| 49 | 4 | 100 |  |  |  | 19 | if ( exists $opts{id} ) { | 
|  |  | 50 |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | $cus = Net::Flotum::Object::Customer->new( | 
| 51 |  |  |  |  |  |  | flotum => $self, | 
| 52 |  |  |  |  |  |  | id     => $opts{id} | 
| 53 | 2 |  |  |  |  | 52 | ); | 
| 54 | 2 | 100 |  |  |  | 1204 | $cus->_load_from_id unless $lazy; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | elsif ( exists $opts{remote_id} ) { | 
| 57 | 2 |  |  |  |  | 66 | $cus = Net::Flotum::Object::Customer->new( | 
| 58 |  |  |  |  |  |  | flotum => $self, | 
| 59 |  |  |  |  |  |  | id     => '_ID_IS_REQUIRED_' | 
| 60 |  |  |  |  |  |  | ); | 
| 61 | 2 |  |  |  |  | 82 | $cus->_load_from_remote_id( $opts{remote_id} ); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  | else { | 
| 64 | 0 |  |  |  |  | 0 | croak 'missing parameter: `remote_id` or `id` is required'; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 2 |  |  |  |  | 9 | return $cus; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub new_customer { | 
| 71 | 2 |  |  | 2 | 0 | 5112 | my ( $self, %opts ) = @_; | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 2 |  |  |  |  | 103 | my $customer_id = $self->customer_api->exec_new_customer(%opts); | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 2 |  |  |  |  | 37 | return Net::Flotum::Object::Customer->new( | 
| 76 |  |  |  |  |  |  | flotum => $self, | 
| 77 |  |  |  |  |  |  | %$customer_id | 
| 78 |  |  |  |  |  |  | ); | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub _new_charge { | 
| 82 | 1 |  |  | 1 |  | 3 | my $self = shift; | 
| 83 | 1 |  |  |  |  | 41 | return $self->charge_api->exec_new_charge(@_); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | sub _update_customer { | 
| 87 | 1 |  |  | 1 |  | 2 | my $self = shift; | 
| 88 | 1 |  |  |  |  | 28 | return $self->customer_api->exec_update_customer(@_); | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | sub _payment_charge { | 
| 92 | 1 |  |  | 1 |  | 3 | my $self = shift; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 1 |  |  |  |  | 28 | return $self->charge_api->exec_payment_charge(@_); | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | sub _capture_charge { | 
| 98 | 1 |  |  | 1 |  | 3 | my $self = shift; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 1 |  |  |  |  | 72 | return $self->charge_api->exec_capture_charge(@_); | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub _refund_charge { | 
| 104 | 1 |  |  | 1 |  | 2 | my $self = shift; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 1 |  |  |  |  | 24 | return $self->charge_api->exec_refund_charge(@_); | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub _get_customer_data { | 
| 110 | 6 |  |  | 6 |  | 23 | my ( $self, %opts ) = @_; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | confess 'missing parameter: `remote_id` or `id` is required' | 
| 113 |  |  |  |  |  |  | unless ( exists $opts{remote_id} && defined $opts{remote_id} ) | 
| 114 | 6 | 50 | 66 |  |  | 58 | || ( exists $opts{id} && defined $opts{id} ); | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 66 |  |  |  |  | 
| 115 |  |  |  |  |  |  |  | 
| 116 | 6 |  |  |  |  | 131 | return $self->customer_api->exec_load_customer(%opts); | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | sub _get_customer_session_key { | 
| 121 | 1 |  |  | 1 |  | 4 | my ( $self, %opts ) = @_; | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | confess 'missing parameter: `id` is required' | 
| 124 | 1 | 50 | 33 |  |  | 14 | unless ( exists $opts{id} && defined $opts{id} ); | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 1 |  |  |  |  | 29 | return $self->customer_api->exec_get_customer_session(%opts)->{api_key}; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | sub _get_list_customer_credit_cards { | 
| 130 | 1 |  |  | 1 |  | 4 | my ( $self, %opts ) = @_; | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | confess 'missing parameter: `id` is required' | 
| 133 | 1 | 50 | 33 |  |  | 9 | unless ( exists $opts{id} && defined $opts{id} ); | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 1 |  |  |  |  | 25 | my $arr = $self->customer_api->exec_list_credit_cards(%opts)->{credit_cards}; | 
| 136 | 1 | 50 |  |  |  | 10 | return wantarray ? @$arr : $arr; | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | sub _remove_customer_credit_cards { | 
| 140 | 1 |  |  | 1 |  | 5 | my ( $self, %opts ) = @_; | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | confess 'missing parameter: `id` is required' | 
| 143 | 1 | 50 | 33 |  |  | 10 | unless ( exists $opts{id} && defined $opts{id} ); | 
| 144 |  |  |  |  |  |  | confess 'missing parameter: `merchant_customer_id` is required' | 
| 145 | 1 | 50 | 33 |  |  | 8 | unless ( exists $opts{merchant_customer_id} && defined $opts{merchant_customer_id} ); | 
| 146 |  |  |  |  |  |  |  | 
| 147 | 1 |  |  |  |  | 25 | my $bool = $self->customer_api->exec_remove_credit_card(%opts); | 
| 148 | 1 |  |  |  |  | 7 | return $bool; | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | 1; | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | __END__ |