#!/usr/bin/perl #Sample PayPal Button Encryption: Copyright 2006,2007 StellarWebSolutions.com #Not for resale - license agreement at #http://www.stellarwebsolutions.com/en/eula.php #Updated: 2007 01 10 use IPC::Open2; #for open2 command $MY_KEY_FILE = "/usr/home/user/my-prvkey.pem"; #private key $MY_CERT_FILE = "/usr/home/user/my-pubcert.pem"; #signing certificate $PAYPAL_CERT_FILE = "/usr/home/user/paypal_sandbox.pem"; #PayPal certificate $OPENSSL = "/usr/bin/openssl"; #openssl command my %hash = ('cmd' => '_cart', 'business' => 'paypala@accounthere.com', 'cert_id' => 'ABCDEF1234567', 'notify_url' => '', 'return' => '', 'shopping_url' => '', 'cancel_return' => '', 'rm' => $rm, 'lc' => 'US', 'custom' => 'customfield', 'invoice' => '', #must be unique 'currency_code' => 'USD', #or USD 'upload' => '1', 'no_shipping' => '1', 'item_name' => 'Stellar Cart', 'item_number' => '12345', 'item_name_1' => 'ebook A', 'amount_1' => '10.00', 'quantity_1' => '1', 'item_number_1' => '111111', 'shipping_1' => '0', 'item_name_2' => 'Software B', 'amount_2' => '39.99', 'quantity_2' => '2', 'item_number_2' => '222222', 'shipping_2' => '0', 'on0_1' => 'Delivery', 'os0_1' => 'Electronic Download', 'on1_1' => 'OS', 'os1_1' => 'Linux', 'item_name_3' => 'ebook C', 'amount_3' => '69.69', 'quantity_3' => '1', 'item_number_3' => '333333', 'shipping_3' => '0', ); my $encrypted = paypal(%hash); # print encrypted button form print < Sample Shopping Cart using PayPal Encrypted Buttons

Checkout

Buy Now using PayPal!

HTML_HEADER exit(1); sub paypal ($) { #Sample PayPal Button Encryption: Copyright 2006,2007 StellarWebSolutions.com #Not for resale - license agreement at #http://www.stellarwebsolutions.com/en/eula.php #Updated: 2007 01 10 my (%dat) = @_; $dat{ 'bn' } = 'StellarWebSolutions.PERL_EWP'; my $pid = open2(*READER, *WRITER, "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " . "-outform der -nodetach -binary | $OPENSSL smime -encrypt " . "-des3 -binary -outform pem $PAYPAL_CERT_FILE") || die "$OPENSSL: failed: $!\n"; for my $key ( keys %dat ) { if ($dat{$key} ne "") { print WRITER "$key=$dat{$key}\n"; } }; close(WRITER); # get encrypted data my @lines = ; close(READER); # get string of encrypted data my $encrypted = join('', @lines); return $encrypted };