File Coverage

blib/lib/Net/Braintree/Configuration.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Net::Braintree::Configuration;
2              
3 1     1   308 use Net::Braintree::Gateway;
  0            
  0            
4             use Moose;
5              
6             has merchant_id => (is => 'rw');
7             has partner_id => (is => 'rw');
8             has public_key => (is => 'rw');
9             has private_key => (is => 'rw');
10             has gateway => (is => 'ro', lazy => 1, default => sub { Net::Braintree::Gateway->new({config => shift})});
11              
12             has environment => (
13             is => 'rw',
14             trigger => sub {
15             my ($self, $new_value, $old_value) = @_;
16             if ($new_value !~ /integration|development|sandbox|production|qa/) {
17             warn "Assigned invalid value to Net::Braintree::Configuration::environment";
18             }
19             if ($new_value eq "integration") {
20             $self->public_key("integration_public_key");
21             $self->private_key("integration_private_key");
22             $self->merchant_id("integration_merchant_id");
23             }
24             }
25             );
26              
27             sub base_merchant_path {
28             my $self = shift;
29             return "/merchants/" . $self->merchant_id;
30             }
31              
32             sub base_merchant_url {
33             my $self = shift;
34             return $self->base_url() . $self->base_merchant_path;
35             }
36              
37             sub base_url {
38             my $self = shift;
39             return $self->protocol . "://" . $self->server . ':' . $self->port;
40             }
41              
42             sub port {
43             my $self = shift;
44             if($self->environment =~ /integration|development/) {
45             return $ENV{'GATEWAY_PORT'} || "3000"
46             } else {
47             return "443";
48             }
49             }
50              
51             sub server {
52             my $self = shift;
53             return "localhost" if $self->environment eq 'integration';
54             return "localhost" if $self->environment eq 'development';
55             return "api.sandbox.braintreegateway.com" if $self->environment eq 'sandbox';
56             return "api.braintreegateway.com" if $self->environment eq 'production';
57             return "qa-master.braintreegateway.com" if $self->environment eq 'qa';
58             }
59              
60             sub auth_url {
61             my $self = shift;
62             return "http://auth.venmo.dev:9292" if $self->environment eq 'integration';
63             return "http://auth.venmo.dev:9292" if $self->environment eq 'development';
64             return "https://auth.sandbox.venmo.com" if $self->environment eq 'sandbox';
65             return "https://auth.venmo.com" if $self->environment eq 'production';
66             return "https://auth.qa.venmo.com" if $self->environment eq 'qa';
67             }
68              
69             sub ssl_enabled {
70             my $self = shift;
71             return ($self->environment !~ /integration|development/);
72             }
73              
74             sub protocol {
75             my $self = shift;
76             return $self->ssl_enabled ? 'https' : 'http';
77             }
78              
79             sub api_version {
80             return "4";
81             }
82              
83             1;