[ic] PayPalExpress Signature and Token?

Steve Graham icdev at mrlock.com
Wed Apr 22 01:22:44 UTC 2009

Here is the version I am using, but it does not have a version number in the 
Maybe you can sort out the differences..... I'm sure Lyn has a newer 


# Vend::Payment::PaypalExpress - Interchange Paypal Express Payments module
# Copyright (C) 2006 Zolotek Resources Ltd
# All Rights Reserved.
# Author: Lyn St George <info at zolotek.net>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA  02111-1307  USA.
package Vend::Payment::PaypalExpress;

=head1 NAME

Vend::Payment::PaypalExpress - Interchange Paypal Express Payments Module


    IO::Socket::SSL   (version 0.97 until 0.99x is fixed for the "illegal 
seek" error, or a later one that works)

Test for current installations with: perl -MSOAP::Lite -e 'print "It 


The Vend::Payment::PaypalExpress module implements the paypalexpress() 
for use with Interchange, performing these actions:

1/ take a 'sale', 'order', 'authorization'.
2/ make a 'refund'
3/ make a 'capture', 'auth' or 'reauth' on an 'order' or 'authorization' 
4/ make a 'masspay' payment to several recipients (max 250) simultaneously. 
5/ handle IPN messages from recurring payments or other operations.  TODO

Some of these actions require a suitable terminal interface. Such a terminal 
is available at
http://kiwi.zolotek.net, along with the current version of this module. 
Paypal have their own
virtual terminal, but state that it is "only available in the USA". This 
release of the module
has had the 'TODO' bits removed, but these will be put back when I get 
around to getting them finished.



Quick start:

Place this module in <ic_root>/lib/Vend/Payment, and call it in 
<ic_root>/interchange.cfg with
Require module Vend::Payment::PaypalExpress. Ensure that your perl 
installation contains the modules
listed above and their pre-requisites.

Logon to your Paypal Business (not Personal) account and go to 'Profile' -> 
'API access' ->
'Request API Credential' -> 'Signature'. This will generate a user id, 
password and signature.

Add to catalog.cfg all marked 'required', optionally the others:
Route  paypalexpress id   xxx  (required_
Route  paypalexpress password xxx  (required)
Route  paypalexpress signature xxx (required: use the 3-token system, not 
the certificate system at Paypal)
Route  paypalexpress returnurl your_full_URL/paypalgetrequest (required)
Route  paypalexpress cancelurl your_full_URL/your_cancellation_page 
Route  paypalexpress host api.sandbox.paypal.com  (for testing)
Route  paypalexpress host api-3t.paypal.com (required: live host, one of 
this or the above but not both)
Route  paypalexpress currency EUR|GBP|USD|CAD|AUD  (optional, defaults to 
Route  paypalexpress pagestyle (optional, set up at Paypal)
Route  paypalexpress paymentaction Sale (optional, defaults to 'Sale')
Route  paypalexpress headerimg 'secure URL' (optional, though must be served 
from a secure URL if used)

Optionally, you may set the return URL in the page as
<input type=hidden name=returnurl value=your_url>,
and similarly the cancelurl may be set in the page.

To have Paypal co-operate with your normal payment service provider, eg 
Authorizenet, do the following:

Deactivate the MV_PAYMENT_MODE variable in catalog.cfg and 

Add to etc/profiles.order:
__NAME__                       paypalexpress
&fatal = yes
&set=mv_payment PaypalExpress
&set=psp Paypal
&set=mv_payment_route paypalexpress
&final = yes
&setcheck = payment_method paypalexpress

Within the 'credit_card' section of etc/profiles.order change both instances 
and add
&set=psp __MV_PAYMENT_BANK__
&set=mv_payment_route authorizenet
(or your preferred gateway) as the last entries in the section.

and then add
Variable MV_PAYMENT_BANK "foo"
to catalog.cfg, where "foo" is the name of your gateway or acquirer, 
formatted as you want it to appear
on the receipt. Eg, "Bank of America" (rather than boa), "AuthorizeNet" 
(rather than authorizenet).

In etc/log_transction, change
[elsif variable MV_PAYMENT_MODE] to [elsif value mv_order_profile eq 
and within the same section change the following two instances of
[var MV_PAYMENT_MODE] to [value mv_payment_route]

Just after the credit_card section, add the following:

[elsif value mv_order_profile eq paypalexpresss]
		return if $Scratch->{tmp_total} == $Scratch->{tmp_remaining};
		my $msg = sprintf "Your Paypal account was charged %.2f", 
		$Scratch->{pay_cert_total} = $Scratch->{tmp_total} - 
		$Scratch->{charge_total_message} = $msg;
		return "Paypal will be charged $Scratch->{tmp_remaining}";
	Charging with payment mode=paypalexpress
	[tmp name="charge_succeed"][charge route="paypalexpress" 
pprequest="dorequest" amount="[scratch tmp_remaining]" order_id="[value 
	[if scratch charge_succeed]
	[set do_invoice]1[/set]
	[set do_payment]1[/set]
	Real-time charge succeeded. ID=[data session payment_id] amount=[scratch 
	Real-time charge FAILED. Reason: [data session payment_error]
			delete $Scratch->{$_};
		die errmsg(
				"Real-time charge failed. Reason: %s\n",
This runs the final Paypal charge route, handles deductions for gift 
certificates from the amount
payable, and handles errors in the same way as the previous credit_card 
section does.

Add into the end of the "[import table=transactions type=LINE continue=NOTES 
no-commit=1]" section
of etc/log_transaction:
psp: [value psp]
pptransactionid: [calc]$result{TransactionID}[/calc]
pprefundtransactionid: [calc]$result->{RefundTransactionID}[/calc]
ppcorrelationid: [calc]$result{CorrelationID};[/calc]
and add these 4 new columns into your transactions table.
You will have records of which transactions went through which payment 
service providers, as well
as Paypal's returned IDs. The CorrelationID is the one you need in any 
dispute with them.

Create a page 'ord/paypalsetrequest.html', and make it the target of any 
'Paypal' buttons or links:
[value name=mv_order_route set=paypalexpress]
[value name="pprequest" set=""]
[charge route="paypalexpress" pprequest="setrequest"]
[if scratch token]
[bounce ord/checkout]

Create a page 'ord/paypalgetrequest.html', and make it the target of the 
returnURL from Paypal:
[charge route="paypalexpress" pprequest="getrequest"]
[bounce ord/paypalcheckout]

Create a page 'paypalcheckout.html' in the pages/ord folder. This should 
display just the basket and address
or whatever you choose for the final pages, plus an IC button with:
			  pprequest = dorequest
in the body part as the submit button to finalise the order.

You may then use PaypalExpress for any transaction where the 
'mv_order_profile' is set to paypalexpress
but still use the "credit_card" 'mv_order_profile' for other transactions, 
eg for Authorizenet. Of
course, if PaypalExpress is to be your only payment method, then simply add:
Variable  MV_PAYMENT_MODE paypalexpress
to catalog.cfg just before the paypalexpress Route entries, and this route 
will be the default.

Note that because Paypal do not recognise UK as a country, only GB, you need 
to setup shipping in
your country.txt for GB as well as UK. Note also that Paypal do not return 
the customer's telephone
number, so you may need to adjust your order profiles to compensate.

The flow is: the first button for Paypal goes to the 'paypalsetrequest' 
page, which sends a request
to Paypal to initialise the transaction and gets a token back in return. If 
Paypal fails to send back
a token, then the module refreshes that page with an error message 
suggesting that the customer should
use your normal payment service provider and shows the cards that you 
accept. Once the token is read, then
your customer is taken to Paypal to login and choose his payment method. 
Once that is done, he returns
to us and hits the 'paypalgetrequest' page. This gets his full address as 
held by Paypal, bounces to
the final 'paypalcheckout' page and populates the form with his address 
details. If you have both shipping
and billing forms on that page, the shipping address will be populated by 
default but you may force
the billing form to be populated instead by sending
<input type=hidden name=pp_use_billing_address value=1>
at the initial 'setrequest' stage. Then the customer clicks the final 'pay 
now' button and the
transaction is done.

Options that may be set either in the route or in the page:
 * reqconfirmshipping - this specifies that a Paypal customer must have his 
address 'confirmed'
 * addressoverride - this specifies that you will ship only to the address 
IC has on file (including
   the name and email); your customer needs to login to IC first before 
going to Paypal
other options are also settable.


=head1 AUTHORS

Lyn St George <info at zolotek.net>
Based on original code by Mike Heins <mheins at perusion.com>


	eval {
		package Vend::Payment;
		require SOAP::Lite or die __PACKAGE__ . " requires SOAP::Lite";
# without this next it defaults to Net::SSL which may crash
		require IO::Socket::SSL or die __PACAKGE__ . "requires IO::Socket::SSL";

	if ($@) {
		$msg = __PACKAGE__ . ' requires SOAP::Lite and IO::Socket::SSL';
		::logGlobal ($msg);
		die $msg;

	::logGlobal("%s payment module loaded",__PACKAGE__)
		unless $Vend::Quiet or ! $Global::VendRoot;

package Vend::Payment;

sub paypalexpress {
 use SOAP::Lite +trace; # debugging only
    my ($token, $header, $request, $method, $response);
    my $actual;
    if ($opt->{actual}){
		$actual = $opt->{actual};
    else {
		my (%actual) = map_actual();
		$actual = \%actual;

#::logGlobal("actual map result: " . ::uneval($actual));
my $pprequest = $::Values->{'pprequest'} || charge_param('pprequest') || 
'setrequest'; # 'setrequest', 'getrequest', 'dorequest'. The final button 
sets 'dorequest' as a value.
my $username  = $::Values->{'id'} || charge_param('id') or die "No username 
my $password  = $::Values->{'password'} || charge_param('password') or die 
"No password\n";
my $signature = $::Values->{'signature'} || charge_param('signature') or die 
"No signature found\n"; # use this as certificate is broken
my $host      = $::Values->{'host'} || charge_param('host') || 
'api-3t.paypal.com'; #  live 3-token system is 'api-3t.paypal.com'.

# ISO currency code, from the page for a multi-currency site or fall back to 
config files.
my $currency = $::Values->{currency_code} || 
$Vend::Cfg->{Locale}{iso_currency_code} ||
                charge_param('currency')  || 
$::Variable->{MV_PAYMENT_CURRENCY} || 'USD';

#my $txtype =  $opt->{transaction} || charge_param(txtype) || 'Sale';

my $amount =  Vend::Interpolate::total_cost() || $::Values->{amount}; # 
   $amount =~ s/^\D*//g;
   $amount =~ s/\s*//g;
   $amount =~ s/,//g;

# for a SET request
my $invoiceID          = $::Values->{inv_no} || 
$::Values->{mv_transaction_id} || $::Values->{order_number} || ''; # 
my $returnURL          = $::Values->{'returnurl'} || 
charge_param('returnurl') or die "No return URL found\n"; # required
my $cancelURL          = $::Values->{'cancelurl'} || 
charge_param('cancelurl') or die "No cancel URL found\n"; # required
my $maxAmount          = $::Values->{maxamount} || '';  # optional
   $maxAmount          = &ppcommify($maxamount);
my $orderDescription   = '';
my $address            = '';
my $reqConfirmShipping = $::Values->{reqconfirmshipping} || 
charge_param('reqconfirmshipping') || ''; # you require that the customer's 
address must be "confirmed"
my $noShipping         = $::Values->{noshipping} || 
charge_param('noshipping') || ''; # no shipping displayed on Paypal pages
my $addressOverride    = $::Values->{addressoverride} || 
charge_param('addressoverride') || ''; # if '1', Paypal displays address 
given in SET request, not the one on Paypal's file
my $localeCode         = $::Values->{localecode} || $::Session->{mv_locale} 
|| charge_param('localecode') || 'en_US';
my $pageStyle          = $::Values->{pagestyle} || charge_param('pagestyle') 
|| ''; # set in Paypal account
my $headerImg          = $::Values->{'headerimg'} || 
charge_param('headerimg') || ''; # from your secure site
my $headerBorderColor  = $::Values->{headerbordercolor} || 
charge_param('headerbordercolor') || '';
my $headerBackColor    = $::Values->{headerbackcolor} || 
charge_param('headerbackcolor') || '';
my $payflowColor       = $::Values->{payflowcolor} || 
charge_param('payflowcolor') || '';
my $paymentAction      = $::Values->{paymentaction} || 
charge_param('paymentaction') || 'Sale'; # others: 'Order', 'Authorization'
my $buyerEmail         = $::Values->{buyeremail} || '';
my $custom             = $Session->{'id'}; # should not be needed
# these next taken from IC after customer has logged in, and used in 
my $name               = "$::Values->{'fname'} $::Values->{'lname'}" || '';
my $address1           = $::Values->{'address1'};
my $address2           = $::Values->{'address2'};
my $city               = $::Values->{'city'};
my $state              = $::Values->{'state'};
my $zip                = $::Values->{'zip'};
my $country            = $::Values->{'country'};
   if ($country eq 'UK') {$country = 'GB'}; # plonkers reject UK

# for a DO request
my $itemTotal     = $::Values->{itemtotal} || Vend::Interpolate::subtotal() 
|| '';
   $itemTotal     = &ppcommify($itemtotal);
my $shipTotal     = $::Values->{shiptotal} || 
Vend::Interpolate::shipping($::Values->{mv_shipmode}) || '';
   $shipTotal     = &ppcommify($shiptotal);
my $taxTotal      = $::Values->{taxtotal} || Vend::Interpolate::salestax() 
|| '';
   $taxTotal      = &ppcommify($taxtotal);
my $handlingTotal = $::Values->{handlingtotal} || Vend::Ship::tag_handling() 
|| '';
   $handlingTotal = &ppcommify($handlingtotal);

my $notifyURL           = $::Values->{notifyurl} || 
charge_param('notifyurl') || ''; # for IPN
my $buttonSource        = $::Values->{buttonsource} || 
charge_param('buttonsource') || ''; # for third party source
my $paymentDetailsItem  = $::Values->{paymentdetailsitem} || 
charge_param('paymentdetailsitem') || ''; # set '1' to include item details
my $transactionID       = $::Values->{transactionid} || ''; # returned upon 
my $correlationID       = $::Values->{correlationid} || ''; # use for any 
dispute with Paypal
my $refundtransactionID = $::Values->{refundtransactionid} || ''; # log for 
my $quantity            = $::Tag->nitems() || '1';

# if $paymentDetailsItem is set, then need to pass an item amount to keep 
Paypal happy
my $itemAmount   = $amount / $quantity;
   $itemAmount   = &ppcommify($itemamount);
   $amount       = &ppcommify($amount);
my $receiverType = $::Values->{receiverType} || charge_param('receivertype') 
|| 'EmailAddress'; # used in MassPay
my $version      = '2.0';

#::logGlobal("quantity=$quantity, itemAmount=$itemAmount, 

    my @override = qw/

    for(@override) {
	next unless defined $opt->{$_};
	$actual->{$_} = $opt->{$_};

    $order_id  = gen_order_id($opt);

# for operations through the payment terminal, eg 'masspay', 'refund' etc
my  $refundType    = $::Values->{refundtype} || 'Full'; # either 'Full' or 
my  $memo          = $::Values->{memo} || '';
my  $orderid       = $::Values->{mv_order_id} || '';
my  $emailSubject  = $::Values->{emailsubject} || ''; # subject line of 
my  $receiverEmail = $::Values->{receiveremail} || ''; # address of refund 

    my %result;

    my $xmlns = 'urn:ebay:api:PayPalAPI';

	    $service = SOAP::Lite->proxy("https://$host/2.0/")->uri($xmlns);
	    # Ignore the paypal typecasting returned
	    *SOAP::Deserializer::typecast = sub {shift; return shift};

### Create the Security Header
	 my $header = SOAP::Header->name("RequesterCredentials" =>
						SOAP::Data->name("Credentials" =>
								SOAP::Data->name("Username" => $username )->type("xs:string"),
								SOAP::Data->name("Password" => $password )->type("xs:string"),
								SOAP::Data->name("Signature" => $signature)->type("xs:string")

### Create a SET request and method, and read response
    if ($pprequest eq 'setrequest') {
		   my @setreq = (
				       SOAP::Data->name("OrderTotal" => 
				       SOAP::Data->name("currencyID" => $currency)->type("xs:string"),
				       SOAP::Data->name("MaxAmount" => $maxAmount)->type("xs:string"),
				       SOAP::Data->name("OrderDescription" => 
				       SOAP::Data->name("Custom" => $custom)->type("xs:string"),
				       SOAP::Data->name("InvoiceID" => $invoiceID)->type("xs:string"),
				       SOAP::Data->name("ReturnURL" => $returnURL)->type("xs:string"),
				       SOAP::Data->name("CancelURL" => $cancelURL)->type("xs:string"),
				       SOAP::Data->name("ReqConfirmShipping" => 
				       SOAP::Data->name("NoShipping" => $noShipping)->type("xs:string"),
				       SOAP::Data->name("AddressOverride" => 
				       SOAP::Data->name("LocaleCode" => $localeCode)->type("xs:string"),
				       SOAP::Data->name("PageStyle" => $pageStyle)->type("xs:string"),
				       SOAP::Data->name("PaymentAction" => $paymentAction)->type(""),
				       SOAP::Data->name("BuyerEmail" => $buyerEmail)->type("xs:string"),
				       SOAP::Data->name("cpp-header-image" => 
				       SOAP::Data->name("cpp-header-border-color" => 
				       SOAP::Data->name("cpp-header-back-color" => 
				       SOAP::Data->name("cpp-payflow-color" => 

           my @setaddress = (
                       SOAP::Data->name("Address" =>
                        SOAP::Data->name("Name" => 
                        SOAP::Data->name("Street1" => 
                        SOAP::Data->name("Street2" => 
                        SOAP::Data->name("CityName" => 
                        SOAP::Data->name("StateOrProvince" => 
                        SOAP::Data->name("PostalCode" => 
                        SOAP::Data->name("Country" => 

# destroy the token here at the start of a new request, rather than after a 
'dorequest' has completed,
# as Paypal use it to reject duplicate payments resulting from clicking the 
final 'pay' button more
# than once.
   undef $::Scratch->{token};
    if (($addressOverride == '1') and ($name)) {
    push @setreq, @setaddress;

		$request = SOAP::Data->name("SetExpressCheckoutRequest" =>
				 SOAP::Data->name("Version" => $version)->type("xs:string"),
				 SOAP::Data->name("SetExpressCheckoutRequestDetails" =>
			     ) ->attr({xmlns=>"urn:ebay:apis:eBLBaseComponents"});

 	    $method = 
	    $response = $service->call($header, $method => $request);
	    		%result = %{$response->valueof('//SetExpressCheckoutResponse')};
				$::Scratch->{token} = $result{Token};

    if (!$::Scratch->{token}){
    my $accepted = uc($::Variable->{CREDIT_CARDS_ACCEPTED});
    $msg = errmsg("Paypal has failed to respond correctly - please use our 
secure payment system instead. We accept $accepted cards");
    $Vend::Session->{errors}{paypalexpress} = $msg;
    push @msg, $msg;
    return @msg;


### Create a GET request and method, and read response
    elsif ($pprequest eq 'getrequest') {
	    $request = SOAP::Data->name("GetExpressCheckoutDetailsRequest" =>
			 SOAP::Data->name("Version" => $version)->type("xs:string"),
		         SOAP::Data->name("Token" => 
		   ) ->attr({xmlns=>"urn:ebay:apis:eBLBaseComponents"});
	     $method = 
	    $response = $service->call($header, $method => $request);
			%result = %{$response->valueof('//GetExpressCheckoutDetailsResponse')};

# populate the billing address rather than shipping address when the basket 
is being shipped to
# another address, eg it is a wish list.
	  if (($result{Ack} eq "Success") and ($::Values->{pp_use_billing_address} 
== 1)) {
		$::Values->{b_phone_day}      = 
		$::Values->{b_email}          = 
		$::Values->{payerid}          = 
		$::Values->{payerstatus}      = 
		$::Values->{payerbusiness}    = 
	    $::Values->{salutation}       = 
	    $::Values->{b_fname}          = 
	    $::Values->{mname}            = 
	    $::Values->{b_lname}          = 
	    $::Values->{suffix}           = 
	    $::Values->{address_status}   = 
	    $::Values->{b_name}           = 
	    $::Values->{b_address1}       = 
	    $::Values->{b_address2}       = 
	    $::Values->{b_city}           = 
	    $::Values->{b_state}          = 
	    $::Values->{b_zip}            = 
	    $::Values->{b_country}        = 
	    $::Values->{countryname}      = 

	  elsif ($result{Ack} eq "Success") {
	    $::Scratch->{paypal_ec} = 1;
	    $::Values->{phone_day}      = 
$result{GetExpressCheckoutDetailsResponseDetails}{ContactPhone} || 
$::Values->{phone_day} || $::Values->{phone_night};
		$::Values->{payerid}        = 
		$::Values->{payerstatus}    = 
		$::Values->{payerbusiness}  = 
	    $::Values->{salutation}     = 
	    $::Values->{suffix}         = 
	    $::Values->{address_status} = 
	  if ($addressOverride != '1') {
		$::Values->{email}          = 
	    $::Values->{name}           = 
	    $::Values->{fname}          = 
	    $::Values->{mname}          = 
	    $::Values->{lname}          = 
	    $::Values->{address1}       = 
	    $::Values->{address2}       = 
	    $::Values->{city}           = 
	    $::Values->{state}          = 
	    $::Values->{zip}            = 
	    $::Values->{country}        = 
	    $::Values->{countryname}    = 
::logGlobal("ln534: pprequest=$pprequest, token=$::Scratch->{token}, 
name=$name, fname=$::Values->{fname},lname=$::Values->{lname}");
### Create a DO request and method, and read response
    elsif ($pprequest eq 'dorequest') {
     #  $currency = 'EUR'; # set to currency different to that started with 
to force failure for testing
	   my @doreq  = (
				     SOAP::Data->name("OrderTotal" => 
$amount )->attr({"currencyID"=>$currency})->type("xs:string"),
				     SOAP::Data->name("ItemTotal" => 
$itemTotal )->attr({"currencyID"=>$currency})->type("xs:string"),
				     SOAP::Data->name("ShippingTotal" => 
$shipTotal )->attr({"currencyID"=>$currency})->type("xs:string"),
				     SOAP::Data->name("HandlingTotal" => 
$handlingTotal )->attr({"currencyID"=>$currency})->type("xs:string"),
				     SOAP::Data->name("TaxTotal" => 
$taxTotal )->attr({"currencyID"=>$currency})->type("xs:string"),
				     SOAP::Data->name("OrderDescription" => 
$orderDescription )->type("xs:string"),
				     SOAP::Data->name("Custom" => $custom )->type("xs:string"),
				     SOAP::Data->name("InvoiceID" => $invoiceID )->type("xs:string")

        my @sta  = (
                    SOAP::Data->name("ShipToAddress" =>
                     SOAP::Data->name("Name" => $name)->type("xs:string"),
                     SOAP::Data->name("Street1" => 
                     SOAP::Data->name("Street2" => 
                     SOAP::Data->name("CityName" => 
                     SOAP::Data->name("StateOrProvince" => 
                     SOAP::Data->name("PostalCode" => 
                     SOAP::Data->name("Country" => 

	    my @pdi  = (
	                SOAP::Data->name("PaymentDetailsItem" =>
	                 SOAP::Data->name("Name" => $name)->type("xs:string"),
	                 SOAP::Data->name("Amount" => 
	                 SOAP::Data->name("Number" => 
	                 SOAP::Data->name("Quantity" => 
	                 SOAP::Data->name("Tax" => $tax)->type("xs:string")

	if ($notifyURL) {push @doreq,SOAP::Data->name("NotifyURL" => 
$notifyURL )->type("xs:string")}
	if ($buttonSource) {push @doreq, SOAP::Data->name("ButtonSource" => 
$buttonSource )->type("xs:string")}
	if ($addressOverride  == '1') {push @doreq, @sta }
	if ($paymentDetailsItem == '1') {push @doreq, @pdi }

	    $request = SOAP::Data->name("DoExpressCheckoutPaymentRequest" =>
			        SOAP::Data->name("Version" => $version)->type("xs:string"),
			        SOAP::Data->name("DoExpressCheckoutPaymentRequestDetails" =>
			         SOAP::Data->name("Token" => 
			         SOAP::Data->name("PaymentAction" => $paymentAction)->type(""),
			         SOAP::Data->name("PayerID" => 
$::Values->{payerid} )->type("xs:string"),
			         SOAP::Data->name("PaymentDetails" =>
			         \SOAP::Data->value( @doreq
		   ) ->attr({xmlns=>"urn:ebay:apis:eBLBaseComponents"});

	    $method = 
	    $response = $service->call($header, $method => $request);
	    %result = %{$response->valueof('//DoExpressCheckoutPaymentResponse')};

	  if ($result{Ack} eq "Success") {
	    $Session->{payment_result}{Status} = 'Success';
	    $result{TransactionID}       = 
	    $result{PaymentStatus}       = 
	    $result{TransactionType}     = 
	    $result{PaymentDate}         = 
	    $result{ParentTransactionID} = 
	    $result{PaymentType}         = 
	    $result{PendingReason}       = 
	    $result{PaymentDate}         = 
	    $result{ReasonCode}          = 
	    $result{FeeAmount}           = 
	    $result{ExchangeRate}        = 

::logGlobal("###ln618: Ack=$result{Ack}, token=$::Scratch->{token}, 
::logGlobal("###ln619: paystatus=$result{PaymentStatus}, 
 	  else  {
	    $result{ErrorCode}    = $result{Errors}{ErrorCode};
	    $result{ShortMessage} = $result{Errors}{ShortMessage};
	    $result{LongMessage}  = $result{Errors}{LongMessage};


# REFUND transaction
	elsif ($pprequest eq 'refund') {

	   my @refreq = (
                    SOAP::Data->name("Version" => 
                    SOAP::Data->name("TransactionID" => 
                    SOAP::Data->name("RefundType" => $refundType)->type(""),
                    SOAP::Data->name("Memo" => $memo)->type("xs:string")

   if ($refundType eq 'Partial') {
    push @refreq,  SOAP::Data->name("Amount" => 

     $request = SOAP::Data->name("RefundTransactionRequest" =>
                \SOAP::Data->value( @refreq
                  ) ->type("ns:RefundTransactionRequestType");

	    $method = 
	    $response = $service->call($header, $method => $request);
	    %result = %{$response->valueof('//RefundTransactionResponse')};
::logGlobal("PP631: sm=$result{Errors}{ShortMesage}, 
	    	if ($result{Ack} eq "Success") {
	    	$result->{RefundTransactionID} = 


    # Interchange names are on the left, Paypal on the right
 my %result_map;
 if ($pprequest eq 'dorequest') {
    %result_map = ( qw/
		   order-id	     		TransactionID
		   pop.order-id			TransactionID
		   pop.timestamp		Timestamp
		   pop.auth-code		Ack
		   pop.status			Ack
		   pop.txn-id			TransactionID
		   pop.refund-txn-id	RefundTransactionID
		   pop.statusdetail		Errors.LongMessage
		   pop.cln-id			CorrelationID

    for (keys %result_map) {
        $result{$_} = $result{$result_map{$_}}
            if defined $result{$result_map{$_}};
#::logGlobal("\nln675: result{ack}=$result{'Ack'}, 

  if ($result{Ack} eq 'Success') {
     if ($pprequest eq 'dorequest') {
   $result{MStatus} = $result{'pop.status'} = 'success';
   $result{'order-id'} ||= $opt->{order_id};
  else {
   $result{MStatus} = $result{'pop.status'} = 'failure';
   $result{'order-id'} = $result{'pop.order-id'} = '';
   $result{MErrMsg} = "code $result{ErrorCode}: $result{LongMessage}\n";

undef $::Values->{pprequest};
undef $::Values->{returnurl};

#::logGlobal("ln694: pri=$result{ShortMessage}");
#::logGlobal("pp response: " . ::uneval(%result));

#::logGlobal("tid=$result{TransactionID} paystatus=$result{PaymentStatus} 
txtype=$result{TransactionType} paydate=$result{PaymentDate} 
corrid=$result{CorrelationID} parenttx=$result{ParentTransaction} 
paytype=$result{PaymentType} pendreason=$result{PendingReason} 
paydate=$result{PaymentDate} reasoncode=$result{ReasonCode} 
feeamount=$result{FeeAmount} exrate=$result{ExchangeRate} END");

    return (%result);


sub ppcommify {
    local($_) = shift;
    $_ = sprintf '%.2f', $_;
    1 while s/^(-?\d+)(\d{3})/$1,$2/;
    return $_;

package Vend::Payment::PaypalExpress;



More information about the interchange-users mailing list