File Coverage

blib/lib/Net/Braintree/ClientTokenGateway.pm
Criterion Covered Total %
statement 15 28 53.5
branch 0 6 0.0
condition n/a
subroutine 5 8 62.5
pod 0 1 0.0
total 20 43 46.5


line stmt bran cond sub pod time code
1             package Net::Braintree::ClientTokenGateway;
2 1     1   5 use Moose;
  1         1  
  1         7  
3 1     1   5669 use Carp qw(confess);
  1         3  
  1         102  
4 1     1   11 use Net::Braintree::Validations qw(verify_params client_token_signature_with_customer_id client_token_signature_without_customer_id);
  1         1  
  1         77  
5 1     1   7 use Net::Braintree::Result;
  1         2  
  1         37  
6 1     1   20514 use URI;
  1         2582  
  1         292  
7              
8             has 'gateway' => (is => 'ro');
9              
10             sub generate {
11 0     0 0   my ($self, $params) = @_;
12 0 0         if ($params) {
13 0 0         confess "ArgumentError" unless $self->_conditionally_verify_params($params);
14 0           $params = {client_token => $params};
15             }
16 0           my $result = $self->_make_request("/client_token", 'post', $params);
17 0           $result->{"response"}->{"client_token"}->{"value"};
18             }
19              
20             sub _make_request {
21 0     0     my($self, $path, $verb, $params) = @_;
22 0           my $response = $self->gateway->http->$verb($path, $params);
23 0           Net::Braintree::Result->new(response => $response);
24             }
25              
26             sub _conditionally_verify_params {
27 0     0     my ($self, $params) = @_;
28              
29 0 0         if (exists $params->{"customer_id"}) {
30 0           verify_params($params, client_token_signature_with_customer_id);
31             } else {
32 0           verify_params($params, client_token_signature_without_customer_id);
33             };
34             }
35              
36             1;