| 1 | package Bluepay::Bluepay20Post; | ||
| 2 | |||
| 3 | $VERSION = '0.10'; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | # Required modules | ||
| 9 | use Digest::MD5 qw(md5_hex); | ||
| 10 | use LWP::UserAgent; | ||
| 11 | use URI::Escape; | ||
| 12 | |||
| 13 | |||
| 14 | ## Bluepay20Post default fields ## | ||
| 15 | my $URL = 'https://secure.bluepay.com/interfaces/bp20Post'; | ||
| 16 | my $MODE = "TEST"; | ||
| 17 | |||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Bluepay::Bluepay20Post | ||
| 22 | |||
| 23 | =head1 VERSION | ||
| 24 | |||
| 25 | Version: 0.10 | ||
| 26 | April 2008 | ||
| 27 | |||
| 28 | =head1 SYNOPSIS | ||
| 29 | |||
| 30 | Bluepay::Bluepay20Post - The BluePay 2.0 Post interface | ||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | Bluepay::Bluepay20Post is a Perl based implementation for interaction with the | ||
| 35 | Bluepay 2.0 Post interface. Bluepay20Post accepts the parameters needed for the | ||
| 36 | Bluepay20Post and sends the Post request to Bluepay via HTTPS. Bluepay20Post | ||
| 37 | has been developed on Windows XP, but should work on any OS where Perl is installed. | ||
| 38 | |||
| 39 | =head1 RUNNING Bluepay::Bluepay20Post | ||
| 40 | |||
| 41 | use Bluepay::Bluepay20Post; | ||
| 42 | |||
| 43 | # Create object | ||
| 44 | my $bp20obj = Bluepay::Bluepay20Post->new(); | ||
| 45 | |||
| 46 | # Assign values | ||
| 47 | $bp20Obj->{ACCOUNT_ID} = "myaccountid"; | ||
| 48 | $bp20Obj->{SECRET_KEY} = 'mysecretkey'; | ||
| 49 | $bp20Obj->{TRANS_TYPE} = 'SALE'; | ||
| 50 | $bp20Obj->{MODE} = 'TEST'; # Default is TEST --> Set to LIVE for live tx | ||
| 51 | $bp20Obj->{AMOUNT} = '3.01'; # ODD returns Approved, EVEN returns Declined in TEST mode | ||
| 52 | $bp20Obj->{PAYMENT_ACCOUNT} = '4111111111111111'; # VISA Test Card | ||
| 53 | $bp20Obj->{CARD_EXPIRE} = '0808'; | ||
| 54 | ## PLEASE REVIEW THE BP20 POST DOCUMENTATION TO SEE ALL REQUIRED/POSSIBLE VALUES | ||
| 55 | ## REFERENCE THEM BY NAME DIRECTLY | ||
| 56 | |||
| 57 | # Post --> Results contains the name value pair string of the response | ||
| 58 | # In this format: TRANS_ID=&STATUS=&AVS=&CVV2=&MESSAGE=&REBID= | ||
| 59 | my $results = $bp20Obj->Post(); | ||
| 60 | |||
| 61 | # Can also retrieve the results directly from the object | ||
| 62 | print $bp20Obj->{TRANS_ID} . "\n"; | ||
| 63 | print $bp20Obj->{STATUS} . "\n"; | ||
| 64 | print $bp20Obj->{AVS} . "\n"; | ||
| 65 | print $bp20Obj->{CVV2} . "\n"; | ||
| 66 | print $bp20Obj->{AVS} . "\n"; | ||
| 67 | print $bp20Obj->{AUTH_CODE} . "\n"; | ||
| 68 | print $bp20Obj->{MESSAGE} . "\n"; | ||
| 69 | print $bp20Obj->{REBID} . "\n"; | ||
| 70 | |||
| 71 | |||
| 72 | =head1 METHODS | ||
| 73 | |||
| 74 | =head2 new | ||
| 75 | |||
| 76 | Creates a new instance of a Bluepay::Bluepay20Post object | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | # New | ||
| 81 | sub new { | ||
| 82 | my $class = shift; | ||
| 83 | my $self = {}; # allocate new hash for object | ||
| 84 | bless($self, $class); | ||
| 85 | |||
| 86 | # Set defaults | ||
| 87 | $self->{URL} = $URL; | ||
| 88 | $self->{MODE} = $MODE; | ||
| 89 | |||
| 90 | # return object | ||
| 91 | return $self; | ||
| 92 | } | ||
| 93 | |||
| 94 | =head2 Post | ||
| 95 | |||
| 96 | Posts the data to the Bluepay::Bluepay20Post interface | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | sub Post { | ||
| 101 | my $self = shift; | ||
| 102 | |||
| 103 | ## Create TAMPER_PROOF_SEAL: | ||
| 104 | # The TAMPER_PROOF_SEAL is an MD5 checksum of your SECRET KEY and a few transaction parameters. | ||
| 105 | # The TAMPER_PROOF_SEAL is currently calculated as follows: | ||
| 106 | # md5(SECRET KEY + ACCOUNT_ID + TRANS_TYPE + AMOUNT + MASTER_ID + NAME1 + PAYMENT_ACCOUNT) | ||
| 107 | # where '+' indicates string concantenation and undefined fields are concantenated as '' (null string) | ||
| 108 | my $TAMPER_PROOF_DATA = ($self->{SECRET_KEY} || '') . ($self->{ACCOUNT_ID} || '') . ($self->{TRANS_TYPE} || '') | ||
| 109 | . ($self->{AMOUNT} || '') . ($self->{MASTER_ID} || '') . ($self->{NAME1} || '') . ($self->{PAYMENT_ACCOUNT} || ''); | ||
| 110 | my $TAMPER_PROOF_SEAL = md5_hex $TAMPER_PROOF_DATA;; | ||
| 111 | |||
| 112 | # Create request (encode) | ||
| 113 | my $request = $self->{URL} . "\?TAMPER_PROOF_SEAL=" . uri_escape($TAMPER_PROOF_SEAL || ''); | ||
| 114 | while ( my ($key, $value) = each(%$self) ) { | ||
| 115 | if ($key eq 'SECRET_KEY') { next; } $request .= "&$key=" . uri_escape($value || ''); | ||
| 116 | } | ||
| 117 | |||
| 118 | # Create Agent | ||
| 119 | my $ua = new LWP::UserAgent; | ||
| 120 | #my $response = $ua->Post("$request"); #OLD | ||
| 121 | my $response = $ua->get("$request"); | ||
| 122 | my $content = $response->content; | ||
| 123 | chomp $content; | ||
| 124 | |||
| 125 | # Parse Response | ||
| 126 | # Split the name-value pairs | ||
| 127 | my @pairs = split(/&/, $content); | ||
| 128 | foreach my $pair (@pairs) { | ||
| 129 | my ($name, $value) = split(/=/, $pair); | ||
| 130 | $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | ||
| 131 | $self->{$name} = $value; | ||
| 132 | } | ||
| 133 | |||
| 134 | # Return | ||
| 135 | return $content; | ||
| 136 | } | ||
| 137 | |||
| 138 | =head1 MODULES | ||
| 139 | |||
| 140 | This script has some dependencies that need to be installed before it | ||
| 141 | can run. You can use cpan to install the modules. They are: | ||
| 142 | - Digest::MD5 | ||
| 143 | - LWP::UserAgent | ||
| 144 | - URI::Escape | ||
| 145 | |||
| 146 | =head1 AUTHOR | ||
| 147 | |||
| 148 | The Bluepay::Bluepay20Post perl module was written by Christopher Kois <ckois@bluepay.com>. | ||
| 149 | |||
| 150 | =head1 COPYRIGHTS | ||
| 151 | |||
| 152 | The Bluepay::Bluepay20Post package is Copyright (c) April, 2008 by BluePay, Inc. | ||
| 153 | http://www.bluepay.com All rights reserved. You may distribute this module under the terms | ||
| 154 | of GNU General Public License (GPL). | ||
| 155 | |||
| 156 | Module Copyrights: | ||
| 157 | - The Digest::MD5 module is Copyright (c) 1998-2003 Gisle Aas. | ||
| 158 | Available at: http://search.cpan.org/~gaas/Digest-MD5-2.36/MD5.pm | ||
| 159 | - The LWP::UserAgent module is Copyright (c) 1995-2008 Gisle Aas. | ||
| 160 | Available at: http://search.cpan.org/~gaas/libwww-perl-5.812/lib/LWP/UserAgent.pm | ||
| 161 | - The URI::Escape module is Copyright (c) 1995-2004 Gisle Aas. | ||
| 162 | Available at: http://search.cpan.org/~gaas/URI-1.36/URI/Escape.pm | ||
| 163 | |||
| 164 | NOTE: Each of these modules may have other dependencies. The modules listed here are | ||
| 165 | the modules that Bluepay::Bluepay20Post specifically references. | ||
| 166 | |||
| 167 | =head1 SUPPORT/WARRANTY | ||
| 168 | |||
| 169 | Bluepay::Bluepay20Post is free Open Source software. This code is Free. You may use it, modify it, | ||
| 170 | redistribute it, Post it on the bathroom wall, or whatever. If you do make modifications that are | ||
| 171 | useful, Bluepay would love it if you donated them back to us! | ||
| 172 | |||
| 173 | =head1 KNOWN BUGS: | ||
| 174 | |||
| 175 | This is version 0.10 of Bluepay::Bluepay20Post. There are currently no known bugs. | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | 1; |