lib/WebService/Braintree/Validations.pm

filter: Statementstmt 84.8% 28 / 33 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 11 totaltotal 71.8% 51 / 71 CC 8 SCAR 13.2
CC
8
Cov
89%
verify_params
8.0
search_results_signature
2.0
transaction_search_results_signature
2.0
CRAP 3.7
« lib/WebService/Braintree/AddressGateway.pm ↑ Summary lib/WebService/Braintree/Role/MakeRequest.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package # hide from pause
4 WebService::Braintree::Validations;
5  
6 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use WebService::Braintree::Util qw(is_hashref);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 22 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 our @ISA = qw(Exporter);
13  
14 22 our @EXPORT_OK = qw(
15 verify_params
16 address_signature
17 client_token_signature_with_customer_id
18 client_token_signature_without_customer_id
19 credit_card_signature
20 credit_card_verification_signature
21 customer_signature
22 transaction_signature
23 clone_transaction_signature
24 merchant_account_signature
25 transaction_search_results_signature
26 );
27  
28 # verify_params() ensures:
29 # * the keys of $params are a subset of the keys of white_list
30 # * if the value of a key in either is a hashref, then:
31 # * both must be hashrefs
32 # * verify_params() holds for the values
33 # Edge cases:
34 # * if $params->{$key} is a hashref, the white_list can also be _any_key_. This
35 # disables checking for the keys of $params->{$key}.
36  
37 # This does a "return 0" instead of a "return" so that the tests are easier to
38 # write. Also, this forces scalar context on the returned value.
39 20 ▶sub verify_params {
Subroutine verify_params: called CC=8 SCAR=20.8
Pod undocumented
40 20 my ($params, $white_list) = @_;
41  
42 20 foreach my $key (keys %$params) {
43 21 ▶ return 0 unless exists $white_list->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $white_list->{$key} 11 10 21
44  
45 10 ▶ if (is_hashref($white_list->{$key})) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_hashref($white_list->{$key})) { } 3 7 10
elsif (is_hashref($params->{$key})) { } 3 4 7
46 3 ▶ return 0 unless is_hashref($params->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless is_hashref($params->{$key}) 1 2 3
47 2 ▶ return 0 unless verify_params($params->{$key}, $white_list->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless verify_params($params->{$key}, $white_list->{$key}) 1 1 2
48 } elsif (is_hashref($params->{$key})) {
49 3 ▶ return 0 if $white_list->{$key} ne '_any_key_';
Branch: 1 branch
BranchTrueFalseTotal
if $white_list->{$key} ne "_any_key_" 2 1 3
50 }
51 }
52  
53 5 return 1;
54 }
55  
56 0 ▶sub search_results_signature {
Subroutine search_results_signature: not called CC=1 SCAR=6.9
Pod undocumented
57 return {
58 0 page_size => 1,
59 ids => 1,
60 };
61 }
62  
63 0 ▶sub transaction_search_results_signature {
Subroutine transaction_search_results_signature: not called CC=1 SCAR=6.9
Pod undocumented
64 return {
65 0 search_results => search_results_signature,
66 };
67 }
68  
69 5 ▶sub address_signature {
Subroutine address_signature: called CC=1 SCAR=0.0
Pod undocumented
70 return {
71 5 company => 1,
72 country_code_alpha2 => 1,
73 country_code_alpha3 => 1,
74 country_code_numeric => 1,
75 country_name => 1,
76 extended_address => 1,
77 first_name => 1,
78 options => {
79 update_existing => 1,
80 },
81 last_name => 1,
82 locality => 1,
83 postal_code => 1,
84 region => 1,
85 street_address => 1,
86 };
87 }
88  
89 0 ▶sub client_token_signature_with_customer_id {
Subroutine client_token_signature_with_customer_id: not called CC=1 SCAR=6.9
Pod undocumented
90 return {
91 0 %{client_token_signature_without_customer_id()},
92 customer_id => 1,
93 options => {
94 make_default => 1,
95 fail_on_duplicate_payment_method => 1,
96 verify_card => 1,
97 },
98 };
99 }
100  
101 4 ▶sub client_token_signature_without_customer_id {
Subroutine client_token_signature_without_customer_id: called CC=1 SCAR=0.0
Pod undocumented
102 return {
103 4 proxy_merchant_id => 1,
104 version => 1,
105 merchant_account_id => 1,
106 };
107 }
108  
109 2 ▶sub credit_card_signature {
Subroutine credit_card_signature: called CC=1 SCAR=0.0
Pod undocumented
110 return {
111 2 customer_id => 1,
112 billing_address_id => 1,
113 cardholder_name => 1,
114 cvv => 1,
115 expiration_date => 1,
116 expiration_month => 1,
117 expiration_year => 1,
118 number => 1,
119 token => 1,
120 venmo_sdk_payment_method_code => 1,
121 payment_method_nonce => 1,
122 device_session_id => 1,
123 device_data => 1,
124 fraud_merchant_id => 1,
125 options => {
126 make_default => 1,
127 verification_merchant_account_id => 1,
128 verify_card => 1,
129 update_existing_token => 1,
130 fail_on_duplicate_payment_method => 1,
131 venmo_sdk_session => 1,
132 },
133 billing_address => address_signature,
134 };
135 }
136  
137 1 ▶sub customer_signature {
Subroutine customer_signature: called CC=1 SCAR=0.0
Pod undocumented
138 return {
139 1 company => 1,
140 email => 1,
141 fax => 1,
142 first_name => 1,
143 id => 1,
144 last_name => 1,
145 phone => 1,
146 website => 1,
147 device_data => 1,
148 device_session_id => 1,
149 fraud_merchant_id => 1,
150 credit_card => credit_card_signature,
151 payment_method_nonce => 1,
152 custom_fields => '_any_key_'
153 };
154 }
155  
156 1 ▶sub clone_transaction_signature {
Subroutine clone_transaction_signature: called CC=1 SCAR=0.0
Pod undocumented
157 return {
158 1 amount => 1,
159 channel => 1,
160 options => {
161 submit_for_settlement => 1,
162 },
163 };
164 }
165  
166 0 ▶sub credit_card_verification_signature {
Subroutine credit_card_verification_signature: not called CC=1 SCAR=6.9
Pod undocumented
167 return {
168 0 options => {
169 amount => 1,
170 merchant_account_id => 1,
171 },
172 credit_card => {
173 cardholder_name => 1,
174 cvv => 1,
175 expiration_date => 1,
176 expiration_month => 1,
177 expiration_year => 1,
178 number => 1,
179 billing_address => address_signature,
180 },
181 }
182 }
183  
184 1 ▶sub transaction_signature{
Subroutine transaction_signature: called CC=1 SCAR=0.0
Pod undocumented
185 return {
186 1 amount => 1,
187 customer_id => 1,
188 merchant_account_id => 1,
189 order_id => 1,
190 channel => 1,
191 payment_method_token => 1,
192 payment_method_nonce => 1,
193 device_session_id => 1,
194 device_data => 1,
195 fraud_merchant_id => 1,
196 billing_address_id => 1,
197 purchase_order_number => 1,
198 recurring => 1,
199 shipping_address_id => 1,
200 type => 1,
201 tax_amount => 1,
202 tax_exempt => 1,
203 credit_card => {
204 token => 1,
205 cardholder_name => 1,
206 cvv => 1,
207 expiration_date => 1,
208 expiration_month => 1,
209 expiration_year => 1,
210 number => 1,
211 },
212 customer => {
213 id => 1,
214 company => 1,
215 email => 1,
216 fax => 1,
217 first_name => 1,
218 last_name => 1,
219 phone => 1,
220 website => 1,
221 } ,
222 billing => address_signature,
223 shipping => address_signature,
224 options => {
225 store_in_vault => 1,
226 store_in_vault_on_success => 1,
227 submit_for_settlement => 1,
228 add_billing_address_to_payment_method => 1,
229 store_shipping_address_in_vault => 1,
230 venmo_sdk_session => 1,
231 hold_in_escrow => 1,
232 payee_email => 1,
233 },
234 paypal_account => {
235 payee_email => 1,
236 },
237 custom_fields => '_any_key_',
238 descriptor => {
239 name => 1,
240 phone => 1,
241 url => 1,
242 },
243 subscription_id => 1,
244 venmo_sdk_payment_method_code => 1,
245 service_fee_amount => 1,
246 three_d_secure_token => 1,
247 line_items => 1,
248 };
249 }
250  
251 22 1;
252 __END__
« lib/WebService/Braintree/AddressGateway.pm ↑ Summary lib/WebService/Braintree/Role/MakeRequest.pm »