@@ -172,39 +172,51 @@ Plans: {
172
172
Coupons: {
173
173
Basic_successful_use: {
174
174
my $id = " coupon-$future_ymdhms " ;
175
- my $coupon = $stripe -> post_coupon (
175
+ my %coupon_args = (
176
176
id => $id ,
177
177
percent_off => 50,
178
178
duration => ' repeating' ,
179
179
duration_in_months => 3,
180
180
max_redemptions => 5,
181
181
redeem_by => time () + 100,
182
+ metadata => {
183
+ ' somemetadata' => ' hello world' ,
184
+ },
182
185
);
183
- isa_ok $coupon , ' Net::Stripe::Coupon' ,
184
- ' I love it when a coupon comes together' ;
185
- is $coupon -> id, $id , ' coupon id is the same' ;
186
+ my $coupon = $stripe -> post_coupon( %coupon_args );
187
+ isa_ok $coupon , ' Net::Stripe::Coupon' ;
188
+ for my $f ( sort ( keys ( %coupon_args ) ) ) {
189
+ is_deeply $coupon -> $f , $coupon_args {$f }, " coupon $f matches" ;
190
+ }
186
191
187
192
my $newcoupon = $stripe -> get_coupon(coupon_id => $id );
188
- isa_ok $newcoupon , ' Net::Stripe::Coupon' ,
189
- ' I love it when another coupon comes together' ;
193
+ isa_ok $newcoupon , ' Net::Stripe::Coupon' ;
190
194
is $newcoupon -> id, $id , ' coupon id was encoded correctly' ;
191
- is( $newcoupon -> $_ , $coupon -> $_ , " $_ matches " )
192
- for qw/ id percent_off duration duration_in_months
193
- max_redemptions redeem_by / ;
195
+ for my $f ( sort ( keys ( %coupon_args ) ) ) {
196
+ is_deeply $newcoupon -> $f , $coupon -> $f , " $f matches for both coupon " ;
197
+ }
194
198
195
199
my $coupons = $stripe -> get_coupons(limit => 1);
196
200
is scalar (@{$coupons -> data}), 1, ' got just one coupon' ;
197
201
is $coupons -> get(0)-> id, $id , ' coupon id matches' ;
198
202
199
203
my $hash = $stripe -> delete_coupon($coupon );
200
204
ok $hash -> {deleted }, ' delete response indicates delete was successful' ;
201
- # swallow the expected warning rather than have it print out durring tests.
202
- close STDERR ;
203
- open (STDERR , " >" , " /dev/null" );
204
- eval { $stripe -> get_coupon(coupon_id => $id ) };
205
- ok $@ , " no longer can fetch deleted coupons" ;
206
- close STDERR ;
207
- open (STDERR , " >&" , STDOUT );
205
+ is $hash -> {id }, $id , ' deleted id is correct' ;
206
+ eval {
207
+ # swallow the expected warning rather than have it print out during tests.
208
+ local $SIG {__WARN__ } = sub {};
209
+ $stripe -> get_coupon(coupon_id => $id );
210
+ };
211
+ if ($@ ) {
212
+ my $e = $@ ;
213
+ isa_ok $e , ' Net::Stripe::Error' , ' error raised is an object' ;
214
+ is $e -> type, ' invalid_request_error' , ' error type' ;
215
+ is $e -> message, " No such coupon: $id " , ' error message' ;
216
+ } else {
217
+ fail " no longer can fetch deleted coupons" ;
218
+
219
+ }
208
220
}
209
221
}
210
222
0 commit comments