+ # Pull the current time, to the micro-second from Time::HiRes
+ # Reverse the time string, so when trimed to 13 digits, the most
+ # significant digits, the microseconds, are preserved
+ #
+ # Collission testing:
+ # If a collission were to occur, two Bambora payment profiles would
+ # be created with the same customer_number token. This would result in
+ # both payment profiles declining transactions.
+ # I generated 1,000,000 tokens with this method in 18 seconds.
+ # and they were all unique. I think the risk of collission is minimal.
+ # If this did become a problem for somebody, a time delay could be added
+ # to this method to eliminate the change of collisions:
+ #
+ # sleep(1);
+
+ my $timestr =
+ join '' =>
+ grep { /\d/ }
+ reverse
+ split //, sprintf '%.5f', Time::HiRes::time();
+ my $token = 99 . substr( $timestr, 0, 13 );
+ my @token = split //, $token;
+
+ # Generate Luhn checksum digit
+ my $sum = 0;
+ for my $i ( 0..14 ) {
+ if ( $i % 2 ) {
+ $sum += $token[$i];
+ } else {
+ my $j = $token[$i]*2;
+ $j -= 9 if $j > 9;
+ $sum += $j;
+ }