File Coverage

blib/lib/WebService/Braintree/ClientTokenGateway.pm
Criterion Covered Total %
statement 15 25 60.0
branch 0 6 0.0
condition n/a
subroutine 5 7 71.4
pod 0 1 0.0
total 20 39 51.2


line stmt bran cond sub pod time code
1             package WebService::Braintree::ClientTokenGateway;
2             $WebService::Braintree::ClientTokenGateway::VERSION = '0.92';
3 1     1   6 use Moose;
  1         2  
  1         5  
4             with 'WebService::Braintree::Role::MakeRequest';
5              
6 1     1   5432 use Carp qw(confess);
  1         2  
  1         52  
7 1     1   5 use WebService::Braintree::Validations qw(verify_params client_token_signature_with_customer_id client_token_signature_without_customer_id);
  1         2  
  1         47  
8 1     1   5 use WebService::Braintree::Result;
  1         2  
  1         16  
9 1     1   371 use URI;
  1         2007  
  1         141  
10              
11             has 'gateway' => (is => 'ro');
12              
13             sub generate {
14 0     0 0   my ($self, $params) = @_;
15 0 0         if ($params) {
16 0 0         confess "ArgumentError" unless $self->_conditionally_verify_params($params);
17 0           $params = {client_token => $params};
18             }
19 0           my $result = $self->_make_request("/client_token", 'post', $params);
20 0           $result->{"response"}->{"client_token"}->{"value"};
21             }
22              
23              
24             sub _conditionally_verify_params {
25 0     0     my ($self, $params) = @_;
26              
27 0 0         if (exists $params->{"customer_id"}) {
28 0           verify_params($params, client_token_signature_with_customer_id);
29             } else {
30 0           verify_params($params, client_token_signature_without_customer_id);
31             };
32             }
33              
34             __PACKAGE__->meta->make_immutable;
35             1;
36