summaryrefslogtreecommitdiff
path: root/LedgerSMB/CreditCard/TrustCommerce.pm
blob: b57d2f7a717398e0a0305c6fae564025ff8b8d59 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Simple TrustCommerce API using Net::TCLink
  16. package TrustCommerce;
  17. use LedgerSMB::CreditCard::TrustCommerce::Config ();
  18. use LedgerSMB::CreditCard::Config ();
  19. use Net::TCLink;
  20. %baseparams = ${Config::baseparams};
  21. $debug = ${Config::debug};
  22. sub sale {
  23. $form = shift @_;
  24. my %params = %baseparams;
  25. $params{action} = 'sale';
  26. $params{amount} = $form->{amount} * 100;
  27. $params{track1} = $form->{track1};
  28. $params{track2} = $form->{track2};
  29. &process;
  30. }
  31. sub process {
  32. my %result = Net::TCLink::send(\%params);
  33. $form->{status} = $result{status};
  34. if ($result{status} eq 'decline'){
  35. $form->{declinetype} = $result{declinetype};
  36. $form->{declinemsg} = $declinemsg{$result{declinetype}};
  37. }
  38. $form->{ccauth} = $result{transID};
  39. # log transID and status
  40. print STDERR "Info: TCLink CC AUTH transID $result{transid} returned ".
  41. "status $result{status}:$result{declinetype}:$result{baddata}:".
  42. "$result{errortype}\n";
  43. if ($debug){
  44. print STDERR "Full Result:\n";
  45. for (keys %result){
  46. print "$_= ".$result{$_}."\n";
  47. }
  48. }
  49. %result;
  50. }
  51. sub credit {
  52. $form = shift @_;
  53. my %params = %baseparams;
  54. $params{transid} = $form->{transid};
  55. $params{amount} = $form->{amount};
  56. &process;
  57. }
  58. %declinemsg = (
  59. decline => 'Transaction declined by bank',
  60. avs => 'AVS failed: Address and/or Zip mismatch',
  61. cvv => 'CVV2 Failure: Check the CVV2 number and try again',
  62. call => 'Call customer service number on card to get authcode',
  63. expiredcard => 'This card has expired',
  64. carderror => 'This card number is invalid.',
  65. authexpired => 'The authorization expired. Can not postauth.',
  66. fraud => 'CrediGuard Fraud Score exceeded desired threshold',
  67. blacklist => 'CrediGuard Declined: blacklisted this transaction.',
  68. velocity => 'Crediguard declined: Too many transactions',
  69. dailylimit => 'Too many transactions in a day.',
  70. weeklylimit => 'Too many transactions in a week',
  71. monthlylimit => 'Too many transactions in a month'
  72. );
  73. 1;