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