line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Braintree::TransparentRedirectGateway; |
2
|
1
|
|
|
1
|
|
4
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
3813
|
use Carp qw(confess); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
775
|
use DateTime; |
|
1
|
|
|
|
|
293651
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
8
|
use Net::Braintree::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
7
|
1
|
|
|
1
|
|
416
|
use Net::Braintree::Digest qw(hexdigest); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
322
|
use Net::Braintree::HTTP; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Net::Braintree::Result; |
10
|
|
|
|
|
|
|
use Net::Braintree::TransparentRedirect::QueryString; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'gateway' => (is => 'ro'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub confirm { |
15
|
|
|
|
|
|
|
my ($self, $query_string) = @_; |
16
|
|
|
|
|
|
|
my $qs = Net::Braintree::TransparentRedirect::QueryString->new(config => $self->gateway->config); |
17
|
|
|
|
|
|
|
$qs->validate($query_string); |
18
|
|
|
|
|
|
|
my $params = $qs->parse($query_string); |
19
|
|
|
|
|
|
|
$self->_make_request("/transparent_redirect_requests/". $params->{id} . "/confirm", "post", undef); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub transaction_data { |
23
|
|
|
|
|
|
|
my ($self, $params) = @_; |
24
|
|
|
|
|
|
|
$self->requires($params, qw(redirect_url transaction)); |
25
|
|
|
|
|
|
|
$self->requires_type($params); |
26
|
|
|
|
|
|
|
$params->{'kind'} = 'create_transaction'; |
27
|
|
|
|
|
|
|
return $self->data_string($params); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub create_customer_data { |
31
|
|
|
|
|
|
|
my ($self, $params) = @_; |
32
|
|
|
|
|
|
|
$self->requires($params, qw(redirect_url)); |
33
|
|
|
|
|
|
|
$params->{'kind'} = 'create_customer'; |
34
|
|
|
|
|
|
|
return $self -> data_string($params); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub update_customer_data { |
38
|
|
|
|
|
|
|
my ($self, $params) = @_; |
39
|
|
|
|
|
|
|
$self->requires($params, qw(redirect_url customer_id)); |
40
|
|
|
|
|
|
|
$params->{'kind'} = 'update_customer'; |
41
|
|
|
|
|
|
|
return $self->data_string($params); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub create_credit_card_data { |
45
|
|
|
|
|
|
|
my ($self, $params) = @_; |
46
|
|
|
|
|
|
|
$self->requires($params, qw(redirect_url credit_card)); |
47
|
|
|
|
|
|
|
confess "ArgumentError: credit card must be associated with a customer" unless $params->{'credit_card'}->{'customer_id'}; |
48
|
|
|
|
|
|
|
$params->{'kind'} = 'create_payment_method'; |
49
|
|
|
|
|
|
|
return $self->data_string($params); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub update_credit_card_data { |
53
|
|
|
|
|
|
|
my ($self, $params) = @_; |
54
|
|
|
|
|
|
|
$self->requires($params, qw(redirect_url payment_method_token)); |
55
|
|
|
|
|
|
|
$params->{'kind'} = 'update_payment_method'; |
56
|
|
|
|
|
|
|
return $self->data_string($params); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub url { |
60
|
|
|
|
|
|
|
return shift->gateway->config->base_merchant_url . "/transparent_redirect_requests"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub requires { |
64
|
|
|
|
|
|
|
my ($self, $params, @required) = @_; |
65
|
|
|
|
|
|
|
foreach my $field (@required) { |
66
|
|
|
|
|
|
|
confess "ArgumentError: $field is required" unless $params->{$field} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub requires_type { |
71
|
|
|
|
|
|
|
my ($self, $params) = @_; |
72
|
|
|
|
|
|
|
confess "ArgumentError: Transaction type is required" unless $params->{'transaction'}->{'type'} ; |
73
|
|
|
|
|
|
|
if ($params->{'transaction'}->{'type'} ne 'sale' && |
74
|
|
|
|
|
|
|
$params->{'transaction'}->{'type'} ne 'credit') { |
75
|
|
|
|
|
|
|
confess "ArgumentError: Transaction type must be credit or sale"; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub time_string { |
80
|
|
|
|
|
|
|
my $dt = DateTime->now; |
81
|
|
|
|
|
|
|
return $dt -> strftime("%Y%m%d%H%M%S"); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub data_string { |
85
|
|
|
|
|
|
|
my ($self, $params) = @_; |
86
|
|
|
|
|
|
|
$params->{'api_version'} = $self->gateway->config->api_version; |
87
|
|
|
|
|
|
|
$params->{'time'} = time_string; |
88
|
|
|
|
|
|
|
$params->{'public_key'} = $self->gateway->config->public_key; |
89
|
|
|
|
|
|
|
return $self->build_tr_data($params); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub build_tr_data { |
93
|
|
|
|
|
|
|
my ($self, $params) = @_; |
94
|
|
|
|
|
|
|
my $query = hash_to_query_string($params); |
95
|
|
|
|
|
|
|
my $tr_hash = hexdigest($self->gateway->config->private_key, $query); |
96
|
|
|
|
|
|
|
return "$tr_hash|$query"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _make_request { |
100
|
|
|
|
|
|
|
my($self, $path, $verb, $params) = @_; |
101
|
|
|
|
|
|
|
my $response = $self->gateway->http->$verb($path, $params); |
102
|
|
|
|
|
|
|
my $result = Net::Braintree::Result->new(response => $response); |
103
|
|
|
|
|
|
|
return $result; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |