- # get the payment
- my $cust_pay = $fs->qsearchs('cust_pay',{ custnum => $cust_main->custnum });
- isa_ok ( $cust_pay, 'FS::cust_pay', "$adj payment" ) or BAIL_OUT('');
+ # create customer
+ my $cust_main = $fs->new_customer($adj.'X'.$noun);
+ isa_ok ( $cust_main, 'FS::cust_main', "$adj $noun customer" ) or BAIL_OUT('');
+
+ # insert customer
+ $err = $cust_main->insert;
+ ok( !$err, "insert $adj $noun customer" ) or BAIL_OUT($err);
+
+ # add card
+ my $cust_payby;
+ my %card = random_card();
+ $err = $cust_main->save_cust_payby(
+ %card,
+ payment_payby => $card{'payby'},
+ auto => 1,
+ saved_cust_payby => \$cust_payby
+ );
+ ok( !$err, "save $adj $noun card" ) or BAIL_OUT($err);
+
+ # retrieve card
+ isa_ok ( $cust_payby, 'FS::cust_payby', "$adj $noun card" ) or BAIL_OUT('');
+
+ # check that card tokenized or not
+ if ($tokenizing) {
+ ok( $cust_payby->tokenized, "new $noun cust card tokenized" ) or BAIL_OUT('');
+ } else {
+ ok( !$cust_payby->tokenized, "new $noun cust card not tokenized" ) or BAIL_OUT('');
+ }