[ic] Using charge inside of [perl] [/perl] or UserTag
Shawn Mathews
interchange-users@icdevgroup.org
Fri Oct 18 17:05:01 2002
This is a multi-part message in MIME format.
------=_NextPart_000_0000_01C2760C.E0DFBE80
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
-----Original Message-----
From: interchange-users-admin@icdevgroup.org
[mailto:interchange-users-admin@icdevgroup.org]On Behalf Of Kevin Walsh
Sent: Thursday, October 17, 2002 6:38 PM
To: interchange-users@icdevgroup.org
Subject: RE: [ic] Using charge inside of [perl] [/perl] or UserTag
Shawn Mathews [shawn@oceanebi.com] wrote:
>
> My payment module is attached. (I basically copied the Authorizenet module
> and made changes to support the processor EZIC http://www.ezic.com)
>
You forgot to attach it. :-)
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin@cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
------=_NextPart_000_0000_01C2760C.E0DFBE80
Content-Type: application/octet-stream;
name="Ezic.pm"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Ezic.pm"
# Vend::Payment::Ezic - Interchange Ezic support=0A=
#=0A=
# $Id: Ezic.pm,v 2.1.2.4 2002/04/27 20:58:29 kwalsh Exp $=0A=
#=0A=
# Copyright (C) 1999-2002 Red Hat, Inc. <interchange@redhat.com>=0A=
#=0A=
# by shawn@oceanebi.com with code reused and inspired by=0A=
# mark@summersault.com =0A=
# Mike Heins <mheins@redhat.com>=0A=
# webmaster@nameastar.net=0A=
# Jeff Nappi <brage@cyberhighway.net>=0A=
# Paul Delys <paul@gi.alaska.edu>=0A=
# Edited by Ray Desjardins <ray@dfwmicrotech.com>=0A=
# This program is free software; you can redistribute it and/or modify=0A=
# it under the terms of the GNU General Public License as published by=0A=
# the Free Software Foundation; either version 2 of the License, or=0A=
# (at your option) any later version.=0A=
#=0A=
# This program is distributed in the hope that it will be useful,=0A=
# but WITHOUT ANY WARRANTY; without even the implied warranty of=0A=
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A=
# GNU General Public License for more details.=0A=
#=0A=
# You should have received a copy of the GNU General Public=0A=
# License along with this program; if not, write to the Free=0A=
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,=0A=
# MA 02111-1307 USA.=0A=
# Connection routine for Ezic version 3 using the 'ADC Direct Response'=0A=
# method.=0A=
# Reworked extensively to support new Interchange payment stuff by Mike =
Heins=0A=
package Vend::Payment::Ezic;=0A=
=3Dhead1 Interchange Ezic Support=0A=
=0A=
Vend::Payment::Ezic $Revision: 2.1.2.4 $=0A=
=0A=
=3Dhead1 SYNOPSIS=0A=
=0A=
&charge=3Dezic=0A=
=0A=
or=0A=
=0A=
[charge mode=3Dezic param1=3Dvalue1 param2=3Dvalue2]=0A=
=0A=
=3Dhead1 PREREQUISITES=0A=
=0A=
Net::SSLeay=0A=
=0A=
or=0A=
=0A=
LWP::UserAgent and Crypt::SSLeay=0A=
=0A=
Only one of these need be present and working.=0A=
=0A=
=3Dhead1 DESCRIPTION=0A=
=0A=
The Vend::Payment::Ezic module implements the ezic() routine=0A=
for use with Interchange. It is compatible on a call level with the other=0A=
Interchange payment modules -- in theory (and even usually in practice) =
you=0A=
could switch from CyberCash to Authorize.net with a few configuration =0A=
file changes.=0A=
=0A=
To enable this module, place this directive in C<interchange.cfg>:=0A=
=0A=
Require module Vend::Payment::Ezic=0A=
=0A=
This I<must> be in interchange.cfg or a file included from it.=0A=
=0A=
Make sure CreditCardAuto is off (default in Interchange demos).=0A=
=0A=
The mode can be named anything, but the C<gateway> parameter must be set=0A=
to C<ezic>. To make it the default payment gateway for all credit=0A=
card transactions in a specific catalog, you can set in C<catalog.cfg>:=0A=
=0A=
Variable MV_PAYMENT_MODE ezic=0A=
=0A=
It uses several of the standard settings from Interchange payment. Any =
time=0A=
we speak of a setting, it is obtained either first from the tag/call =
options,=0A=
then from an Interchange order Route named for the mode, then finally a=0A=
default global payment variable, For example, the C<id> parameter would=0A=
be specified by:=0A=
=0A=
[charge mode=3Dezic id=3DYourEzicID]=0A=
=0A=
or=0A=
=0A=
Route ezic id YourEzicID=0A=
=0A=
or =0A=
=0A=
Variable MV_PAYMENT_ID YourEzicID=0A=
=0A=
The active settings are:=0A=
=0A=
=3Dover 4=0A=
=0A=
=3Ditem id=0A=
=0A=
Your Authorize.net account ID, supplied by Authorize.net when you sign =
up.=0A=
Global parameter is MV_PAYMENT_ID.=0A=
=0A=
=3Ditem secret=0A=
=0A=
Your Authorize.net account password, supplied by Authorize.net when you =
sign up.=0A=
Global parameter is MV_PAYMENT_SECRET. This may not be needed for=0A=
actual charges.=0A=
=0A=
=3Ditem referer=0A=
=0A=
A valid referering url (match this with your setting on =
secure.authorize.net).=0A=
Global parameter is MV_PAYMENT_REFERER.=0A=
=0A=
=3Ditem transaction=0A=
=0A=
The type of transaction to be run. Valid values are:=0A=
=0A=
Interchange Ezic=0A=
---------------- -----------------=0A=
auth AUTH_ONLY=0A=
return CREDIT=0A=
reverse PRIOR_AUTH_CAPTURE=0A=
sale AUTH_CAPTURE=0A=
settle CAPTURE_ONLY=0A=
void VOID=0A=
=0A=
=3Ditem remap =0A=
=0A=
This remaps the form variable names to the ones needed by Authorize.net. =
See=0A=
the C<Payment Settings> heading in the Interchange documentation for use.=0A=
=0A=
=3Ditem test=0A=
=0A=
Set this to C<TRUE> if you wish to operate in test mode, i.e. set the =
Authorize.net=0A=
C<x_Test_Request> query paramter to TRUE.i=0A=
=0A=
Examples: =0A=
=0A=
Route ezic test TRUE=0A=
or=0A=
Variable MV_PAYMENT_TEST TRUE=0A=
or =0A=
[charge mode=3Dezic test=3DTRUE]=0A=
=0A=
=3Dback=0A=
=0A=
=3Dhead2 Troubleshooting=0A=
=0A=
Try the instructions above, then enable test mode. A test order should =
complete.=0A=
=0A=
Disable test mode, then test in various Authorize.net error modes by=0A=
using the credit card number 4222 2222 2222 2222.=0A=
=0A=
Then try a sale with the card number C<4111 1111 1111 1111>=0A=
and a valid expiration date. The sale should be denied, and the reason =
should=0A=
be in [data session payment_error].=0A=
=0A=
If nothing works:=0A=
=0A=
=3Dover 4=0A=
=0A=
=3Ditem *=0A=
=0A=
Make sure you "Require"d the module in interchange.cfg:=0A=
=0A=
Require module Vend::Payment::Ezic=0A=
=0A=
=3Ditem *=0A=
=0A=
Make sure either Net::SSLeay or Crypt::SSLeay and LWP::UserAgent are =
installed=0A=
and working. You can test to see whether your Perl thinks they are:=0A=
=0A=
perl -MNet::SSLeay -e 'print "It works\n"'=0A=
=0A=
or=0A=
=0A=
perl -MLWP::UserAgent -MCrypt::SSLeay -e 'print "It works\n"'=0A=
=0A=
If either one prints "It works." and returns to the prompt you should be =
OK=0A=
(presuming they are in working order otherwise).=0A=
=0A=
=3Ditem *=0A=
=0A=
Check the error logs, both catalog and global.=0A=
=0A=
=3Ditem *=0A=
=0A=
Make sure you set your payment parameters properly. =0A=
=0A=
=3Ditem *=0A=
=0A=
Try an order, then put this code in a page:=0A=
=0A=
<XMP>=0A=
[calc]=0A=
my $string =3D $Tag->uneval( { ref =3D> =
$Session->{payment_result} });=0A=
$string =3D~ s/{/{\n/;=0A=
$string =3D~ s/,/,\n/g;=0A=
return $string;=0A=
[/calc]=0A=
</XMP>=0A=
=0A=
That should show what happened.=0A=
=0A=
=3Ditem *=0A=
=0A=
If all else fails, Red Hat and other consultants are available to help=0A=
with integration for a fee.=0A=
=0A=
=3Dback=0A=
=0A=
=3Dhead1 BUGS=0A=
=0A=
There is actually nothing *in* Vend::Payment::Ezic. It changes packages=0A=
to Vend::Payment and places things there.=0A=
=0A=
=3Dhead1 AUTHORS=0A=
=0A=
Mark Stosberg <mark@summersault.com>, based on original code by Mike =
Heins=0A=
<mheins@redhat.com>.=0A=
=0A=
=3Dhead1 CREDITS=0A=
=0A=
Jeff Nappi <brage@cyberhighway.net>=0A=
Paul Delys <paul@gi.alaska.edu>=0A=
webmaster@nameastar.net=0A=
Ray Desjardins <ray@dfwmicrotech.com>=0A=
Nelson H. Ferrari <nferrari@ccsc.com>=0A=
=0A=
=3Dcut=0A=
=0A=
BEGIN {=0A=
=0A=
my $selected;=0A=
eval {=0A=
package Vend::Payment;=0A=
require URI::Escape;=0A=
import URI::Escape qw(uri_unescape);=0A=
};=0A=
my $uri_escape;=0A=
$uri_escape =3D 1 unless $@;=0A=
unless ($uri_escape =3D=3D 1) {=0A=
die __PACKAGE__ . " requires URI::Escape";=0A=
}=0A=
=0A=
eval {=0A=
package Vend::Payment;=0A=
require Net::SSLeay;=0A=
import Net::SSLeay qw(post_https make_form make_headers);=0A=
$selected =3D "Net::SSLeay";=0A=
};=0A=
=0A=
$Vend::Payment::Have_Net_SSLeay =3D 1 unless $@;=0A=
=0A=
unless ($Vend::Payment::Have_Net_SSLeay) {=0A=
=0A=
eval {=0A=
package Vend::Payment;=0A=
require LWP::UserAgent;=0A=
require HTTP::Request::Common;=0A=
require Crypt::SSLeay;=0A=
import HTTP::Request::Common qw(POST);=0A=
$selected =3D "LWP and Crypt::SSLeay";=0A=
};=0A=
=0A=
$Vend::Payment::Have_LWP =3D 1 unless $@;=0A=
=0A=
}=0A=
=0A=
unless ($Vend::Payment::Have_Net_SSLeay or $Vend::Payment::Have_LWP) {=0A=
die __PACKAGE__ . " requires Net::SSLeay or Crypt::SSLeay";=0A=
}=0A=
=0A=
::logGlobal("%s payment module initialized, using %s", __PACKAGE__, =
$selected)=0A=
unless $Vend::Quiet;=0A=
=0A=
}=0A=
=0A=
package Vend::Payment;=0A=
sub ezic {=0A=
my ($user, $amount) =3D @_;=0A=
=0A=
my $opt;=0A=
if(ref $user) {=0A=
$opt =3D $user;=0A=
$account_id =3D $opt->{account_id} || undef;=0A=
$site_id =3D $opt->{site_id} || undef;=0A=
$site_tag =3D $opt->{site_tag} || undef;=0A=
}=0A=
else {=0A=
$opt =3D {};=0A=
}=0A=
my $remote_host =3D $Vend::Session->{ohost};=0A=
my $actual;=0A=
if($opt->{actual}) {=0A=
$actual =3D $opt->{actual};=0A=
}=0A=
else {=0A=
my (%actual) =3D map_actual();=0A=
$actual =3D \%actual;=0A=
}=0A=
=0A=
::logDebug("actual map result: " . ::uneval($actual));=0A=
=0A=
# Try and Get Cart Contents=0A=
my $cartdesc =3D "";=0A=
my $cart =3D $Vend::Session->{carts}->{main};=0A=
foreach my $cartitems (@$cart) {=0A=
$cartdesc .=3D sprintf(qq{ sku =3D %s, qty =3D %s, fmt =3D %s\n},=0A=
$cartitems->{'code'},=0A=
$cartitems->{'quantity'},=0A=
$cartitems->{'formats'}); =0A=
}=0A=
=0A=
=0A=
if (! $user ) {=0A=
$user =3D charge_param('id')=0A=
or return (=0A=
MStatus =3D> 'failure-hard',=0A=
MErrMsg =3D> errmsg('No account id'),=0A=
);=0A=
}=0A=
=0A=
$secret =3D charge_param('secret') if ! $secret;=0A=
=0A=
$opt->{host} ||=3D 'secure.ezic.com';=0A=
=0A=
$opt->{script} ||=3D '/gw/native/direct2.1';=0A=
=0A=
$opt->{port} ||=3D 443;=0A=
=0A=
my $precision =3D $opt->{precision} =0A=
|| 2;=0A=
=0A=
my $referer =3D $opt->{referer}=0A=
|| charge_param('referer');=0A=
=0A=
$actual->{mv_credit_card_exp_month} =3D~ s/\D//g;=0A=
$actual->{mv_credit_card_exp_month} =3D~ s/^0+//;=0A=
$actual->{mv_credit_card_exp_year} =3D~ s/\D//g;=0A=
$actual->{mv_credit_card_exp_year} =3D~ s/\d\d(\d\d)/$1/;=0A=
=0A=
$actual->{mv_credit_card_number} =3D~ s/\D//g;=0A=
=0A=
my $exp =3D sprintf '%02d%02d',=0A=
$actual->{mv_credit_card_exp_month},=0A=
$actual->{mv_credit_card_exp_year};=0A=
=0A=
# Using mv_payment_mode for compatibility with older versions, probably =
not=0A=
# necessary.=0A=
$opt->{transaction} ||=3D 'auth';=0A=
my $transtype =3D $opt->{transaction};=0A=
my $master_id =3D $opt->{master_id};=0A=
my %type_map =3D (=0A=
AUTH_ONLY =3D> 'AUTH',=0A=
CAPTURE_ONLY =3D> 'CAPTURE',=0A=
CREDIT =3D> 'REFUND',=0A=
PRIOR_AUTH_CAPTURE =3D> 'AUTH',=0A=
VOID =3D> 'VOID',=0A=
auth =3D> 'AUTH',=0A=
authorize =3D> 'AUTH',=0A=
mauthcapture =3D> 'CHARGE',=0A=
mauthonly =3D> 'AUTH',=0A=
return =3D> 'RETURN',=0A=
reverse =3D> 'REFUND',=0A=
sale =3D> 'CHARGE',=0A=
settle =3D> 'CAPTURE',=0A=
void =3D> 'VOID',=0A=
);=0A=
=0A=
if (defined $type_map{$transtype}) {=0A=
$transtype =3D $type_map{$transtype};=0A=
}=0A=
=0A=
$amount =3D $opt->{total_cost} if $opt->{total_cost};=0A=
=0A=
if(! $amount) {=0A=
$amount =3D Vend::Interpolate::total_cost();=0A=
$amount =3D Vend::Util::round_to_frac_digits($amount,$precision);=0A=
}=0A=
=0A=
=0A=
# my %query =3D (=0A=
# dCardNumber =3D> $actual->{mv_credit_card_number},=0A=
# dCardName1 =3D> $actual->{b_fname},=0A=
# dCardName2 =3D> $actual->{b_lname},=0A=
# dBillStreet =3D> $actual->{b_address},=0A=
# dBillCity =3D> $actual->{b_city},=0A=
# dBillState =3D> $actual->{b_state},=0A=
# dBillZip =3D> $actual->{b_zip},=0A=
# dBillCountry =3D> $actual->{b_country},=0A=
# dTransType =3D> $transtype,=0A=
# dAmount =3D> $amount,=0A=
# dCardExpire =3D> $exp,=0A=
# dDescription =3D> $cartdesc,=0A=
# dCustomerEmail =3D> $actual->{email},=0A=
# dCustomerPhone =3D> $actual->{phone_day},=0A=
# dAccount =3D> "$account_id:$site_tag"=0A=
#=0A=
# );=0A=
=0A=
my %query =3D ();=0A=
if ($transaction !~ m/(VOID|RETURN|REFUND|CREDIT)/i) {=0A=
$order_id =3D gen_order_id($opt);=0A=
%query =3D (=0A=
CARD_NUMBER =3D> $actual->{mv_credit_card_number},=0A=
CUST_NAME1 =3D> $actual->{b_fname},=0A=
CUST_NAME2 =3D> $actual->{b_lname},=0A=
CUST_ADDR_STREET =3D> $actual->{b_address},=0A=
CUST_ADDR_CITY =3D> $actual->{b_city},=0A=
CUST_ADDR_STATE =3D> $actual->{b_state},=0A=
CUST_ADDR_ZIP =3D> $actual->{b_zip},=0A=
CUST_ADDR_COUNTRY =3D> $actual->{b_country},=0A=
CUST_IP =3D> $remote_host,=0A=
GEN_TRANS_TYPE =3D> $transtype,=0A=
GEN_AMOUNT =3D> $amount,=0A=
CARD_EXPIRE =3D> $exp,=0A=
GEN_DESCRIPTION =3D> $cartdesc,=0A=
CUST_EMAIL =3D> $actual->{email},=0A=
CUST_PHONE =3D> $actual->{phone_day},=0A=
GEN_ACCOUNT =3D> $account_id,=0A=
GEN_SITETAG =3D> $site_tag,=0A=
GEN_PAYMENT_TYPE =3D> 'C',=0A=
DO_MEMBER =3D> 0=0A=
=0A=
);=0A=
} else {=0A=
$order_id =3D $opt->{'order_id'};=0A=
%query =3D ( GEN_ACCOUNT =3D> $account_id,=0A=
GEN_SITETAG =3D> $site_tag,=0A=
GEN_TRANS_TYPE =3D> $transtype,=0A=
GEN_MASTER_ID =3D> $master_id,=0A=
DO_MEMBER =3D> 0=0A=
);=0A=
}=0A=
=0A=
=0A=
=0A=
my @query;=0A=
=0A=
for (keys %query) {=0A=
my $key =3D $_;=0A=
my $val =3D $query{$key};=0A=
$val =3D~ s/["\$\n\r]//g;=0A=
$val =3D~ s/\$//g;=0A=
my $len =3D length($val);=0A=
if($val =3D~ /[&=3D]/) {=0A=
$key .=3D "[$len]";=0A=
}=0A=
push @query, "$key=3D$val";=0A=
}=0A=
my $string =3D join '&', @query;=0A=
=0A=
::logDebug("EziC query: " . ::uneval(\%query));=0A=
$opt->{extra_headers} =3D { Referer =3D> $referer };=0A=
=0A=
my $thing =3D post_data($opt, \%query);=0A=
my $page =3D $thing->{result_page};=0A=
my $response =3D $thing->{status_line};=0A=
# Minivend names are on the left, Authorize.Net on the right=0A=
my %result_map =3D ( qw/=0A=
pop.status RET_STATUS=0A=
pop.error-message RET_AUTH_MSG=0A=
order-id RET_TRANS_ID=0A=
pop.order-id RET_TRANS_ID=0A=
pop.auth-code RET_AUTH_CODE=0A=
pop.avs_code RET_AVS_CODE=0A=
pop.avs_msg RET_AVS_MSG =0A=
pop.cvv2_code RET_CVV2_CODE=0A=
pop.cvv2_msg RET_CVV2_MSG=0A=
/=0A=
);=0A=
=0A=
::logDebug(qq{\nezic page: $page \n\nresponse: $response\n});=0A=
::logGlobal(qq{\nezic page: $page \n\nresponse: $response\n});=0A=
=0A=
my %result=3D ();=0A=
my @tmprslt =3D split('\&',$page);=0A=
foreach my $rslt (@tmprslt) {=0A=
my ($key,$val) =3D split('\=3D',$rslt);=0A=
$result{$key} =3D uri_unescape($val);=0A=
}=0A=
=0A=
#$result{dStatus} =3D $ezic_rsp->param("dStatus");=0A=
#$result{dAuthMessage} =3D $ezic_rsp->param("dAuthMessage");=0A=
#$result{dTransID} =3D $ezic_rsp->param("dTransID");=0A=
#$result{dAuthCode} =3D $ezic_rsp->param("dAuthCode");=0A=
#$result{dAVSCode} =3D $ezic_rsp->param("dAVSCode");=0A=
#$result{dAVSMessage} =3D $ezic_rsp->param("dAVSMessage");=0A=
#$result{dCVV2Code} =3D $ezic_rsp->param("dCVV2Code");=0A=
#$result{dCVV2Message} =3D $ezic_rsp->param("dCVV2Message");=0A=
=0A=
=0A=
=0A=
::logDebug(qq{ezic response_reason_text=3D$result{dAuthMessage} =
response_code: $result{dAuthCode}}); =0A=
=0A=
for (keys %result_map) {=0A=
$result{$_} =3D $result{$result_map{$_}}=0A=
if defined $result{$result_map{$_}};=0A=
}=0A=
=0A=
if ($result{'pop.status'} =3D~ m/(1|T|R)/) {=0A=
$result{MStatus} =3D 'success';=0A=
} else {=0A=
$result{MStatus} =3D 'failure';=0A=
$result{'order-id'} =3D '';=0A=
=0A=
=0A=
# NOTE: A lot more AVS codes could be checked for here.=0A=
if ($result{'pop.avs_code'} eq 'N') {=0A=
my $msg =3D $opt->{message_avs} ||=0A=
qq{You must enter the correct billing address of your credit card. =
The bank returned the following error: %s};=0A=
$result{MErrMsg} =3D errmsg($msg, $result{'pop.avs_msg'});=0A=
} =0A=
=0A=
if ($result{'pop.cvv2_code'} ne 'M') {=0A=
my $msg =3D $opt->{message_cvv2} || =0A=
qq{Your CVV2 Code was not correct: %s};=0A=
$result{MErrMsg} =3D =
$result{MErrMsg}.errmsg($msg,$result{'pop.cvv2_msg'});=0A=
}=0A=
if (($result{'pop.error-message'} ne '') && =
($result{'pop.error-message'} ne 'TEST APPROVED')) {=0A=
my $msg =3D $opt->{message_declined} ||=0A=
"Ezic error: %s. Please call in your order or try again.";=0A=
$result{MErrMsg} =3D errmsg($msg, $result{'pop.error-message'});=0A=
}=0A=
}=0A=
=0A=
return (%result);=0A=
}=0A=
=0A=
package Vend::Payment::Ezic;=0A=
=0A=
1;=0A=
------=_NextPart_000_0000_01C2760C.E0DFBE80--