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   4 use Moose;
  1         1  
  1         7  
3 1     1   4218 use Carp qw(confess);
  1         1  
  1         83  
4 1     1   6 use Net::Braintree::Validations qw(verify_params client_token_signature_with_customer_id client_token_signature_without_customer_id);
  1         1  
  1         48  
5 1     1   4 use Net::Braintree::Result;
  1         2  
  1         15  
6 1     1   538 use URI;
  1         1952  
  1         165  
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;