« lib/WebService/Braintree/TransparentRedirectGateway.pm
↑ Summary
lib/WebService/Braintree/WebhookNotificationGateway.pm »
| 1 | # vim: sw=4 ts=4 ft=perl | ||||||||||||
| 2 | |||||||||||||
| 3 | package WebService::Braintree::Configuration; | ||||||||||||
| 4 | 22 | $WebService::Braintree::Configuration::VERSION = '1.7'; | |||||||||||
| 5 | 22 | ▶ | use 5.010_001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 22 | ▶ | use strictures 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | =head1 NAME | ||||||||||||
| 9 | |||||||||||||
| 10 | WebService::Braintree::Configuration | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 PURPOSE | ||||||||||||
| 13 | |||||||||||||
| 14 | This keeps all configuration information for your WebService::Braintree | ||||||||||||
| 15 | installation. | ||||||||||||
| 16 | |||||||||||||
| 17 | A singleton of this class is instantiated when you use L<WebService::Braintree>. | ||||||||||||
| 18 | You are intended to set attributes of this class immediately, then the rest of | ||||||||||||
| 19 | the distribution knows what to do. | ||||||||||||
| 20 | |||||||||||||
| 21 | =cut | ||||||||||||
| 22 | |||||||||||||
| 23 | 22 | ▶ | use WebService::Braintree::Gateway; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 22 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | |||||||||||||
| 26 | # IS THIS UNUSED? I cannot find reference in the current documentation for Ruby | ||||||||||||
| 27 | # or Node.JS nor is it referenced anywhere else in the code. | ||||||||||||
| 28 | 22 | has partner_id => (is => 'rw'); | |||||||||||
| 29 | |||||||||||||
| 30 | =head1 ATTRIBUTES | ||||||||||||
| 31 | |||||||||||||
| 32 | Get these values from L<Braintree's API credentials documentation|https://articles.braintreepayments.com/control-panel/important-gateway-credentials#api-credentials>. | ||||||||||||
| 33 | |||||||||||||
| 34 | These attributes are standard mutators. If you invoke them with a value, they | ||||||||||||
| 35 | will set the attribute to that value. If you invoke them without a value, they | ||||||||||||
| 36 | will return the current value. | ||||||||||||
| 37 | |||||||||||||
| 38 | =head2 merchant_id(?$value) | ||||||||||||
| 39 | |||||||||||||
| 40 | This is your merchant_id. | ||||||||||||
| 41 | |||||||||||||
| 42 | =cut | ||||||||||||
| 43 | |||||||||||||
| 44 | 22 | has merchant_id => (is => 'rw'); | |||||||||||
| 45 | |||||||||||||
| 46 | =head2 public_key(?$value) | ||||||||||||
| 47 | |||||||||||||
| 48 | This is your public_key. | ||||||||||||
| 49 | |||||||||||||
| 50 | =cut | ||||||||||||
| 51 | |||||||||||||
| 52 | 22 | has public_key => (is => 'rw'); | |||||||||||
| 53 | |||||||||||||
| 54 | =head2 private_key(?$value) | ||||||||||||
| 55 | |||||||||||||
| 56 | This is your private_key. | ||||||||||||
| 57 | |||||||||||||
| 58 | =cut | ||||||||||||
| 59 | |||||||||||||
| 60 | 22 | has private_key => (is => 'rw'); | |||||||||||
| 61 | |||||||||||||
| 62 | =head2 environment(?$value) | ||||||||||||
| 63 | |||||||||||||
| 64 | This is your environment. The environment can be: | ||||||||||||
| 65 | |||||||||||||
| 66 | =over 4 | ||||||||||||
| 67 | |||||||||||||
| 68 | =item development | integration | ||||||||||||
| 69 | |||||||||||||
| 70 | This is when you're using a local server for testing. It's unlikely you will | ||||||||||||
| 71 | ever want to use this. | ||||||||||||
| 72 | |||||||||||||
| 73 | =item sandbox | ||||||||||||
| 74 | |||||||||||||
| 75 | This is when you're using your Braintree sandbox for testing. | ||||||||||||
| 76 | |||||||||||||
| 77 | =item qa | ||||||||||||
| 78 | |||||||||||||
| 79 | This is when you're using qa-master.braintreegateway.com for testing. | ||||||||||||
| 80 | |||||||||||||
| 81 | =item production | ||||||||||||
| 82 | |||||||||||||
| 83 | This is when you're live and rocking. | ||||||||||||
| 84 | |||||||||||||
| 85 | =back | ||||||||||||
| 86 | |||||||||||||
| 87 | If you provide a value other than the ones listed above, a warning will be | ||||||||||||
| 88 | thrown. This distribution will probably not work properly in that case. | ||||||||||||
| 89 | |||||||||||||
| 90 | Management reserves the right to change this from a warning to a thrown | ||||||||||||
| 91 | exception in the future. | ||||||||||||
| 92 | |||||||||||||
| 93 | =head1 USAGE | ||||||||||||
| 94 | |||||||||||||
| 95 | Do yourself a favor and store these values in a configuration file, not your | ||||||||||||
| 96 | source-controlled code. | ||||||||||||
| 97 | |||||||||||||
| 98 | =cut | ||||||||||||
| 99 | |||||||||||||
| 100 | has environment => ( | ||||||||||||
| 101 | is => 'rw', | ||||||||||||
| 102 | 50 | ▶ | trigger => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||
| 103 | 50 | my ($self, $new_value, $old_value) = @_; | |||||||||||
| 104 | 50 | my %valid = map { $_ => 1 } qw( | |||||||||||
| 105 | development integration sandbox qa production | ||||||||||||
| 106 | ); | ||||||||||||
| 107 | 50 | ▶ | if (!$valid{$new_value}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | 1 | warn 'Assigned invalid value to WebService::Braintree::Configuration::environment'; | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | 50 | ▶ | if ($new_value eq 'integration') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | 27 | $self->public_key('integration_public_key'); | |||||||||||
| 113 | 27 | $self->private_key('integration_private_key'); | |||||||||||
| 114 | 27 | $self->merchant_id('integration_merchant_id'); | |||||||||||
| 115 | } | ||||||||||||
| 116 | } | ||||||||||||
| 117 | 22 | ); | |||||||||||
| 118 | |||||||||||||
| 119 | 8 | ▶ | has gateway => (is => 'ro', lazy => 1, default => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 120 | 8 | WebService::Braintree::Gateway->new({config => shift}); | |||||||||||
| 121 | 22 | }); | |||||||||||
| 122 | |||||||||||||
| 123 | # This method is used in ::HTTP | ||||||||||||
| 124 | 5 | ▶ | sub base_merchant_url { | ||||||||||
|
Subroutine
base_merchant_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 125 | 5 | my $self = shift; | |||||||||||
| 126 | 5 | return $self->base_url() . $self->base_merchant_path; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | # Below here, these methods do *NOT* appear to be used outside of this class. | ||||||||||||
| 130 | |||||||||||||
| 131 | 5 | ▶ | sub base_merchant_path { | ||||||||||
|
Subroutine
base_merchant_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 132 | 5 | my $self = shift; | |||||||||||
| 133 | 5 | return '/merchants/' . $self->merchant_id; | |||||||||||
| 134 | } | ||||||||||||
| 135 | |||||||||||||
| 136 | 5 | ▶ | sub base_url { | ||||||||||
|
Subroutine
base_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 137 | 5 | my $self = shift; | |||||||||||
| 138 | 5 | return $self->protocol . '://' . $self->server . ':' . $self->port; | |||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | 26 | ▶ | sub is_development { | ||||||||||
|
Subroutine
is_development: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 142 | 26 | my $self = shift; | |||||||||||
| 143 | 26 | ▶ | return 1 if $self->environment eq 'development'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 144 | 22 | ▶ | return 1 if $self->environment eq 'integration'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 145 | 13 | return; | |||||||||||
| 146 | } | ||||||||||||
| 147 | |||||||||||||
| 148 | 11 | ▶ | sub port { | ||||||||||
|
Subroutine
port: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 149 | 11 | my $self = shift; | |||||||||||
| 150 | 11 | ▶ | if ($self->is_development) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 151 | 7 | ▶ | return $ENV{'GATEWAY_PORT'} || '3000' | ||||||||||
|
Condition100%2/2
$ENV{'GATEWAY_PORT'} || '3000'
MC/DC100%1/1
$ENV{'GATEWAY_PORT'} || '3000'
$ENV{'GATEWAY_PORT'}
Truth table100%2/2
A
A= $ENV{'GATEWAY_PORT'}
| |||||||||||||
| 152 | } else { | ||||||||||||
| 153 | 4 | return 443; | |||||||||||
| 154 | } | ||||||||||||
| 155 | } | ||||||||||||
| 156 | |||||||||||||
| 157 | 10 | ▶ | sub server { | ||||||||||
|
Subroutine
server: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 158 | 10 | my $self = shift; | |||||||||||
| 159 | return { | ||||||||||||
| 160 | development => 'localhost', | ||||||||||||
| 161 | integration => 'localhost', | ||||||||||||
| 162 | sandbox => 'api.sandbox.braintreegateway.com', | ||||||||||||
| 163 | qa => 'qa-master.braintreegateway.com', | ||||||||||||
| 164 | production => 'api.braintreegateway.com', | ||||||||||||
| 165 | 10 | }->{$self->environment}; | |||||||||||
| 166 | } | ||||||||||||
| 167 | |||||||||||||
| 168 | 5 | ▶ | sub auth_url { | ||||||||||
|
Subroutine
auth_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 169 | 5 | my $self = shift; | |||||||||||
| 170 | return { | ||||||||||||
| 171 | development => 'http://auth.venmo.dev:9292', | ||||||||||||
| 172 | integration => 'http://auth.venmo.dev:9292', | ||||||||||||
| 173 | sandbox => 'https://auth.sandbox.venmo.com', | ||||||||||||
| 174 | qa => 'https://auth.qa.venmo.com', | ||||||||||||
| 175 | production => 'https://auth.venmo.com', | ||||||||||||
| 176 | 5 | }->{$self->environment}; | |||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | |||||||||||||
| 180 | 15 | ▶ | sub ssl_enabled { | ||||||||||
|
Subroutine
ssl_enabled: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 181 | 15 | my $self = shift; | |||||||||||
| 182 | 15 | return ! $self->is_development; | |||||||||||
| 183 | } | ||||||||||||
| 184 | |||||||||||||
| 185 | 10 | ▶ | sub protocol { | ||||||||||
|
Subroutine
protocol: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 186 | 10 | my $self = shift; | |||||||||||
| 187 | 10 | ▶ | return $self->ssl_enabled ? 'https' : 'http'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 188 | } | ||||||||||||
| 189 | |||||||||||||
| 190 | =head1 METHODS | ||||||||||||
| 191 | |||||||||||||
| 192 | There is one read-only method. | ||||||||||||
| 193 | |||||||||||||
| 194 | =head2 api_version() | ||||||||||||
| 195 | |||||||||||||
| 196 | This returns the Braintree API version this distribution speaks. | ||||||||||||
| 197 | |||||||||||||
| 198 | =cut | ||||||||||||
| 199 | |||||||||||||
| 200 | # This method is used in ::HTTP | ||||||||||||
| 201 | 5 | ▶ | sub api_version { | ||||||||||
|
Subroutine
api_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 202 | 5 | return "4"; | |||||||||||
| 203 | } | ||||||||||||
| 204 | |||||||||||||
| 205 | 22 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 206 | |||||||||||||
| 207 | 22 | 1; | |||||||||||
| 208 | __END__ | ||||||||||||