1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #!/usr/bin/perl
use SOAP::Lite +trace => 'debug';
$SOAP::Constants::PREFIX_ENV = "soapenv";
my $soap = SOAP::Lite
-> proxy ('<strong>Enter Proxy URL HERE</strong>)
-> on_action( sub {join '', '"urn:Process"',''} )
-> readable(true); # make the XML readable, set this to false or comment out on production
#Change some HTTP Header defaults
$SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE
= 'text/xml';
#Add some custom Name Spaces to the soapenv:Envronment
$soap->serializer->register_ns("http://api.apihost.com/xsd","xmlns:xsd");
$soap->serializer->register_ns("http://api.apihost.com","xmlns:api");
$soap->serializer->register_ns("http://www.w3.org/2005/08/addressing","xmlns:wsa");
#Need todo some funky business with the SoapAction --> See ->on_action as it joins.
$soap->default_ns('api:Process');
$soap->autotype(1);
$soap->outputxml('true');
#setup Username and Password, Get this from your Welcome email.
my $username = "testshayne";
#MD5 password
my $password = "8eee3efdde1eb6cf6639a58848362bf4";
#TODO: create a random word for the nounce, instead of using static base64_encode nounce
my $nonce = "4djRSlpeyWeGzcNgatneSA==";
#TODO: Auto create timestamp
my $timestamp = "2005-2-5T17:18:15Z";
#TODO - Get the digest to work! - This will enable the WSSE Password Digest, instead of using PlainText md5 password
#my $digest = MIME::Base64::encode_base64(Digest::SHA1::sha1(MIME::Base64::decode_base64($nonce) . $timestamp . $password), '');
#Build the WS Security Headers.
my $security=SOAP::Header->name("wsse:Security")->attr({'soapenv:mustUnderstand'=>1,'xmlns:wsse'=>'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'});
my $userToken =SOAP::Header->name("wsse:UsernameToken" =>
\SOAP::Header->value(
SOAP::Header->name('wsse:Username')->value($username)->type(''),
SOAP::Header->name('wsse:Password')->value($password)->type('')->attr({'Type'=>'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'}),
SOAP::Header->name('wsse:Nonce')->value($nonce)->type('')->attr({'EncodingType'=>'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'}),
SOAP::Header->name('wsu:Created')->value($timestamp)->type(''))
)->attr({'xmlns:wsu'=>'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'});
my $address="http://www.w3.org/2005/08/addressing";
my $addressing=SOAP::Header->name("wsa:ReplyTo" => \SOAP::Header->value(SOAP::Header->name('wsa:Address')->value($address)->type('')));
my $action=SOAP::Header->name('wsa:Action')->value('urn:Process')->type('')->attr({'soapenv:mustUnderstand'=>'1'});
my $message=SOAP::Header->name('wsa:MessageID')->value('uuid:7176ecf3-1066-4e97-99da-0aef3f5c12c8')->type('')->attr({'soapenv:mustUnderstand'=>'1'});
#Set minimum values to pass to the API
my $Amount = '100.00';
my $Currency = 'USD';
my $AttemptMode = '1';
my $IPAddress = '192.168.120.157';
my $Email = 'bob10@bob.com';
my $FirstName = 'Bob';
my $LastName = 'Builder';
my $Address1 = '450 Queen St';
my $Address2 = 'City';
my $City = 'Brisbane';
my $State = 'Queensland';
my $Country = 'AU';
my $Postcode = '4000';
my $Phone = 'XXXXXXXX';
my $CardName = 'Bob';
my $CardNumber = 'XXXXXXXXXXXXXXXX';
my $ExpiryMonth = '04';
my $ExpiryYear = '2010';
my $CVV = '123';
my $SiteId = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
my $TestTransaction = 'true';
my $TuringKey = 'XXXXX';
my $Product = 'Shoes';
my $Note = 'Transaction for Shoes';
my $CustomerRef ='wo0t2';
#build the array
my $arrAmount = (\SOAP::Data->value(
SOAP::Data->name('api:Amount')->value($Amount)->type(''),
SOAP::Data->name('api:Currency')->value($Currency)->type('')
));
my $details = (\SOAP::Data->value(
SOAP::Data->name('api:FirstName')->value($FirstName)->type(''),
SOAP::Data->name('api:LastName')->value($LastName)->type(''),
SOAP::Data->name('api:Address1')->value($Address1)->type(''),
SOAP::Data->name('api:Address2')->value($Address2)->type(''),
SOAP::Data->name('api:City')->value($City)->type(''),
SOAP::Data->name('api:State')->value($State)->type(''),
SOAP::Data->name('api:Country')->value($Country)->type(''),
SOAP::Data->name('api:Postcode')->value($Postcode)->type(''),
SOAP::Data->name('api:Phone')->value($Phone)->type(''),
)->type(''));
my $arrCustDetails = (\SOAP::Data->value(
SOAP::Data->name('api:Details')->value($details)->type(''),
SOAP::Data->name('api:CustomerRef')->value($CustomerRef)->type(''),
SOAP::Data->name('api:Email')->value($Email)->type(''),
SOAP::Data->name('api:IPAddress')->value($IPAddress)->type('')
));
my $arrCardDetails = (\SOAP::Data->value(
SOAP::Data->name('api:CardName')->value($CardName)->type(''),
SOAP::Data->name('api:CardNumber')->value($CardNumber)->type(''),
SOAP::Data->name('api:ExpiryMonth')->value($ExpiryMonth)->type(''),
SOAP::Data->name('api:ExpiryYear')->value($ExpiryYear)->type(''),
SOAP::Data->name('api:CVV')->value($CVV)->type('')));
#package the final array
my $params = ( SOAP::Data->value(
SOAP::Data->name('api:CardDetails' => $arrCardDetails),
SOAP::Data->name('api:Customer' => $arrCustDetails),
SOAP::Data->name('api:Amount' => $arrAmount),
SOAP::Data->name('api:AttemptMode')->value($AttemptMode)->type(''),
SOAP::Data->name('api:Note')->value($Note)->type(''),
SOAP::Data->name('api:Product')->value($Product)->type(''),
SOAP::Data->name('api:SiteId')->value($SiteId)->type(''),
SOAP::Data->name('api:TuringKey')->value($TuringKey)->type(''),
SOAP::Data->name('api:TestTransaction')->value($TestTransaction)->type('')
));
#Set the envrionment prefix for Process
$process ='api:Process';
#send our request and process a transaction
print $soap->$process($params, $security->value(\$userToken, $action, $message)); |