问题
I'm trying to get a discount to apply to a shopping cart I've written. I'm using the Adaptive API
system, but I can't seem to get it right. I've tried it in the SetPaymentOptions call:
'receiverOptions' => [
{
'receiver' => {
'email' => 'foo@live.co.uk'
},
'invoiceData' => {
'totalShipping' => '8.00',
'totalTax' => 0,
'item' => [
{
'itemPrice' => '15.00',
'name' => 'Alice in Wonderland Mechanism Necklace',
'price' => '15',
'itemCount' => 1
},
{
'itemPrice' => '30.00',
'name' => '110 Year Old Unicorn Dial Necklace',
'price' => '30',
'itemCount' => 1
}
],
'discount' => '0.15'
}
}
],
'requestEnvelope' => {
'errorLanguage' => 'en_US',
'detailLevel' => 'ReturnAll'
},
'payKey' => 'AP-2F6415163M814733M',
'SenderOptions' => {
'requireShippingAddressSelection' => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' )
}
};
..and even tried it in the initial Pay call - but neither seem to recognise the discount (and apply it).
'currencyCode' => 'GBP',
'requestEnvelope' => {
'errorLanguage' => 'en_US',
'detailLevel' => 'ReturnAll'
},
'cancelUrl' => 'https://sitedev.net/',
'discount' => '0.15',
'actionType' => 'CREATE',
'ipnNotificationUrl' => 'https://sitedev.net/cgi-bin/ipn.cgi',
'returnUrl' => 'https://sitedev.net/myorders',
'reverseAllParallelPaymentsOnError' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
'receiverList' => {
'receiver' => [
{
'email' => 'foo@live.co.uk',
'amount' => '53.00',
'invoiceId' => '47',
'paymentType' => 'GOODS'
}
]
}
};
UPDATE: Mmm ok - still having issues with this!
'item' => [
{
'itemPrice' => '25.00',
'name' => 'Cryptex - 16Gb USB Drive',
'price' => '25',
'itemCount' => 1
},
{
'name' => 'Special Discount',
'price' => '-2.50',
'itemCount' => 1
},
{
'itemPrice' => '5.00',
'name' => 'Shipping',
'price' => '5.00',
'itemCount' => 1
}
]
Thats the values I'm passing in, yet at the cart end, it shows as:
Steampunk Junkies £27.50
Cryptex - 16Gb USB Drive
£25.00
Shipping
£5.00
£0.00
The weird thing - is that the discount IS being applied... just not shown???
回答1:
I'm curious where you see that there's a "discount" parameter even available in these calls..?? It's not listed in the API reference for Pay or SetPaymentOptions.
What you'll need to do is add the discount as a line item in SetPaymentOptions with a negative amount. So it would be an extra line item with -0.15 as the value. You could name the item "discount" or whatever you want, but again, there is no actual discount parameter available in these API's.
来源:https://stackoverflow.com/questions/26817580/paypal-api-discount