1 package Business::OnlineThirdPartyPayment::FCMB;
4 use base 'Business::OnlineThirdPartyPayment';
10 use Date::Format 'time2str';
13 our $VERSION = '0.01';
14 our $ENDPOINT_SANDBOX = 'localhost';
15 our $ENDPOINT_LIVE = 'fcmbwebpay.firstcitygrouponline.com';
19 # ISO 4217 currency codes (the relevant ones)
29 $self->build_subs(qw(username password host));
31 $DEBUG = $args{debug};
40 $params{'orderId'} = time2str('%Y%m%d%H%M%S', time) . '-' .
41 sprintf('%06d', int(rand(1000000)));
42 $params{'mercId'} = $self->username
43 or die "FCMB merchant ID (username) must be configured\n";
44 $params{'currCode'} = $ALPHA_TO_NUM{$content{currency}};
45 $params{'prod'} = $content{'description'};
46 $params{'email'} = $content{'email'};
47 $params{'amt'} = $content{'amount'};
49 my $host = $self->host;
50 if ( $self->test_transaction ) {
51 $host ||= $ENDPOINT_SANDBOX;
53 $host ||= $ENDPOINT_LIVE;
55 my $url = 'https://' . $host .
56 '/customerportal/MerchantServices/MakePayment.aspx';
58 warn Dumper \%params if $DEBUG > 2;
60 # we don't post to the url ourselves, just give it to the user
62 $self->redirect($url);
63 $self->post_params(\%params);
65 $self->token( $params{'orderId'} );
73 # http://merchantA.com/Success?OrderID=988676&TransactionReference=8765678998989779
74 warn Dumper(\%params) if $DEBUG > 2;
76 if ($params{'OrderID'}) {
77 $self->token($params{'OrderID'});
79 die 'No order ID returned from processor';
81 if ($params{'TransactionReference'}) {
82 $self->order_number($params{'TransactionReference'});
84 die 'No transaction reference returned from processor';
87 my $host = $self->host;
88 if ( $self->test_transaction ) {
89 $host ||= $ENDPOINT_SANDBOX;
90 $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
92 $host ||= $ENDPOINT_LIVE;
94 my $url = URI->new('https://' . $host .
95 '/customerportal/MerchantServices/UpayTransactionStatus.ashx');
96 $url->query_form('MERCHANT_ID' => $self->username,
97 'ORDER_ID' => $self->token);
98 my $ua = LWP::UserAgent->new;
99 warn "Querying transaction status at $url\n" if $DEBUG;
100 my $response = $ua->get($url);
102 if ( $response->is_success ) {
105 my $parser = XML::LibXML->new;
106 my $doc = eval { $parser->parse_string($response->content) };
108 die "malformed response to transaction status request: $@\n".
109 ($DEBUG ? ("\n\n".$response->content) : '');
111 my $root = $doc->documentElement;
112 my %hash = map { $_->nodeName => $_->textContent }
113 $root->nonBlankChildNodes;
115 warn Dumper \%hash if $DEBUG > 2;
116 if ( $hash{StatusCode} == 0 ) {
117 $self->is_success(1);
118 $self->authorization($hash{PaymentRef});
120 $self->is_success(0);
121 $self->error_message($hash{Status} . ' - ' . $hash{ResponseDescription});
124 die "No confirmation received: ".$response->status_line;
133 Business::OnlineThirdPartyPayment::FCMB
137 Business::OnlineThirdPartyPayment interface to the First City Monument Bank
138 (Nigeria) web-based payment processing system.
144 =item FCMB requires the callback URL to be configured statically;
145 I<return_url> and I<cancel_url> parameters will be ignored.
147 =item Set I<username> to your merchant ID (5 digits). No password is needed.
149 =item The only required transaction fields are currency (NGN, USD, or UKP),
150 amount, description, and email.
152 =item The 'faker' directory contains a simple mock-up of the FCMB interface
153 for testing. This was created from the documentation, without reference
154 to the real FCMB system, and is NOT known to be accurate.
160 Mark Wells <mark@freeside.biz>
164 perl(1). L<Business::OnlineThirdPartyPayment>.