You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* updated Kavorka signature to remove non-functional argument types
* removed Net::Stripe::Customer and HashRef for customer, as neither form was being serialized correctly for passing to the API call
* removed Net::Stripe::Card and Net::Stripe::Token for card, as neither form was being serialized correctly for passing to the API call
* added in-method validation and unit tests for the different combinations of the allowed argument types
* updated and reorganized failing unit tests
* closes L<#94> and L<#137>
isa_ok $e, 'Net::Stripe::Error', 'error raised is an object';
295
+
is $e->type, 'post_charge error', 'error type';
296
+
like $e->message, qr/^Invalid value 'card_.+' passed for parameter 'card'\. Charges without an existing customer can only accept a token id or card hashref\.$/, 'error message';
297
+
} else {
298
+
fail 'post charge with card id';
299
+
}
300
+
}
301
+
302
+
Post_charge_using_card_hash: {
303
+
my$charge = $stripe->post_charge(
304
+
amount=> 100,
305
+
currency=>'usd',
306
+
card=>$fake_card,
307
+
);
308
+
isa_ok $charge, 'Net::Stripe::Charge';
309
+
ok $charge->paid, 'charge was paid';
310
+
is $charge->status, 'paid', 'charge status is paid';
311
+
is $charge->card->last4, substr( $fake_card->{number}, -4 ), 'charge card last4 matches';
312
+
}
313
+
314
+
Post_charge_for_customer_id_with_attached_card: {
315
+
my$customer = $stripe->post_customer(
316
+
card=>$fake_card,
317
+
);
318
+
my$charge = $stripe->post_charge(
319
+
amount=> 100,
320
+
currency=>'usd',
321
+
customer=>$customer->id,
322
+
);
323
+
isa_ok $charge, 'Net::Stripe::Charge';
324
+
ok $charge->paid, 'charge was paid';
325
+
is $charge->status, 'paid', 'charge status is paid';
326
+
is $charge->card->id, $customer->default_card, 'charged default card';
isa_ok $e, 'Net::Stripe::Error', 'error raised is an object';
364
+
is $e->type, 'post_charge error', 'error type';
365
+
like $e->message, qr/^Invalid value 'tok_.+' passed for parameter 'card'\. Charges for an existing customer can only accept a card id\.$/, 'error message';
366
+
} else {
367
+
fail 'post charge for customer with token id';
368
+
}
369
+
}
370
+
371
+
Post_charge_for_customer_id_using_card_id: {
372
+
# customer may have multiple cards. allow ability to select a specific
373
+
# card for a given charge.
374
+
my$customer = $stripe->post_customer();
375
+
my$card = $stripe->post_card(
376
+
customer=>$customer,
377
+
card=>$fake_card,
378
+
);
379
+
for ( 1..3 ) {
380
+
my$other_card = $stripe->post_card(
381
+
customer=>$customer,
382
+
card=>$fake_card,
292
383
);
293
-
} qr/invalid_request_error/, 'missing card and customer';
is $charge->status, 'paid', 'charge status is paid';
395
+
is $charge->card->id, $card->id, 'charge card id matches';
396
+
}
397
+
398
+
Post_charge_for_customer_id_using_card_hash: {
399
+
my$customer = $stripe->post_customer();
400
+
eval {
401
+
$stripe->post_charge(
402
+
amount=> 100,
403
+
currency=>'usd',
404
+
customer=>$customer->id,
405
+
card=>$fake_card,
406
+
);
407
+
};
408
+
if ($@) {
409
+
my$e = $@;
410
+
isa_ok $e, 'Net::Stripe::Error', 'error raised is an object';
411
+
is $e->type, 'post_charge error', 'error type';
412
+
like $e->message, qr/^Invalid value 'HASH\(0x[0-9a-f]+\)' passed for parameter 'card'. Charges for an existing customer can only accept a card id\.$/, 'error message';
413
+
} else {
414
+
fail 'post charge for customer with card hashref';
415
+
}
416
+
}
294
417
295
-
throws_ok {
418
+
Rainy_day: {
419
+
# swallow the expected warning rather than have it print out during tests.
420
+
local$SIG{__WARN__} = sub {};
421
+
# Test a charge with no source or customer
422
+
eval {
296
423
$stripe->post_charge(
297
424
amount=> 3300,
298
425
currency=>'usd',
299
426
description=>'Wikileaks donation',
300
-
customer=>'fake-customer-id',
301
-
card=> {
302
-
number=>'4242-4242-4242-4242',
303
-
exp_month=>$future->month,
304
-
exp_year=>$future->year,
305
-
cvc=> 123,
306
-
name=>'Anonymous',
307
-
},
308
427
);
309
-
} qr/invalid_request_error/, 'missing card and customer';
428
+
429
+
};
430
+
if ($@) {
431
+
my$e = $@;
432
+
isa_ok $e, 'Net::Stripe::Error', 'error raised is an object';
433
+
is $e->type, 'invalid_request_error', 'error type';
434
+
is $e->message, 'Must provide source or customer.', 'error message';
0 commit comments