PayPal API - discount? - paypal

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???

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.

Related

Perl dynamic hash of hash errors

I am looping over a query and returning results. I am trying to add a hash to another hashes. But running into trouble.
my %users_data;
while($sth->fetch)
{
$mygroup =>
{
'fname' => $fname,
'lname' => $lname,
'address' =>
{
'street' => $street,
'city' => $city,
},
'id' => $uid,
},
}
how do I add the $mygroup hash to %users_data hash?
long hand would be.
my %users_data = (
'salesmanager' =>
{
'fname' => 'mike',
'lname' => 'john',
'address' =>
{
'street' => '123 street',
'city' => 'Brooklyn',
},
'id' => 12,
},
'garagemanager' =>
{
'fname' => 'Mark',
'lname' => 'Jones',
'address' =>
{
'street' => '355 street',
'city' => 'Brooklyn',
},
'id' => 13,
},
)
Simply access the target key and assign its new value:
my %users_data;
while($sth->fetch)
{
$users_data{$mygroup} = {
'fname' => $fname,
'lname' => $lname,
'address' =>
{
'street' => $street,
'city' => $city,
},
'id' => $uid,
};
}

Accessing Specific OTRS Dynamic Field value via SOAP

How do I further access this dynamic field value? Upon using below dumper,
print Dumper( $Body->{$ResponseKey} );
The result is :
$VAR1 = {
'Ticket' => {
'Title' => 'TPLUS Service PIC',
'DynamicField' => [
{
'Value' => '43312',
'Name' => 'BugID'
},
{
'Value' => '6',
'Name' => 'OTRSMV'
},
{
'Value' => '6.13',
'Name' => 'OTRSPLV'
},
{
'Value' => 'Dev',
'Name' => 'OTRSUse'
},
{
'Value' => '2018-03-02 00:28:00',
'Name' => 'RefDate'
},
{
'Value' => '0',
'Name' => 'RefNumber'
},
{
'Value' => '',
'Name' => 'StartTime'
}
],
'StateType' => 'open',
'SLAID' => ''
}
};
How can I access the single value of DynamicField->RefDate ? Thanks
my $fields = $Body->{$ResponseKey}{Ticket}{DynamicField};
my ($ref_date) =
map $_->{Value},
grep $_->{Name} eq 'RefDate',
#$fields;
or
my %fields;
$fields{ $_->{Name} } = $fields{ $_->{Value} }
for #{ $Body->{$ResponseKey}{Ticket}{DynamicField} };
my $ref_date = $fields{RefDate};

ApiGility - Getting validation errors with PUT

I am new to ApiGility and am attempting to update my shopping cart via an API call as apposed to a route. I am using Zend Framework 2 with a code connected api.
The problem I am currently facing is that no matter what I try, I am unable to put the information to the api without validation errors.
My module.config:
Updatecart settings:
'Api\\V1\\Rest\\Updatecart\\Controller' => array(
'listener' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartResource',
'route_name' => 'api.rest.updatecart',
'route_identifier_name' => 'updatecart_id',
'collection_name' => 'updatecart',
'entity_http_methods' => array(
0 => 'GET',
1 => 'PATCH',
2 => 'PUT',
3 => 'DELETE',
),
'collection_http_methods' => array(
0 => 'GET',
1 => 'POST',
2 => 'PUT',
3 => 'PATCH',
4 => 'DELETE',
),
'collection_query_whitelist' => array(
0 => 'prod_id',
1 => 'quantity',
2 => 'quantity_accumulation',
3 => 'tax',
),
'page_size' => 25,
'page_size_param' => null,
'entity_class' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartEntity',
'collection_class' => 'Api\\V1\\Rest\\Updatecart\\UpdatecartCollection',
'service_name' => 'updatecart',
),
Relevant filter settings:
'Api\\V1\\Rest\\Updatecart\\Validator' => array(
0 => array(
'name' => 'prod_id',
'required' => true,
'filters' => array(
0 => array(
'name' => 'Zend\\Filter\\Int',
'options' => array(),
),
),
'validators' => array(),
'description' => 'The id of the product in the cart to be updated',
'error_message' => 'Missing product id',
'allow_empty' => false,
'continue_if_empty' => false,
),
1 => array(
'name' => 'quantity',
'required' => true,
'filters' => array(),
'validators' => array(),
'description' => 'quantity of product',
'error_message' => 'You must include a quantity',
'allow_empty' => false,
'continue_if_empty' => false,
),
2 => array(
'name' => 'tax',
'required' => true,
'filters' => array(),
'validators' => array(),
'description' => 'Add the VAT, GST, Sales Tax that will be applicable to this item. Use 0.00 for no value.',
'error_message' => 'Please add a tax value, 0.00 for no value.',
'allow_empty' => false,
'continue_if_empty' => false,
),
3 => array(
'name' => 'quantity_accumulation',
'required' => true,
'filters' => array(
0 => array(
'name' => 'Zend\\Filter\\Boolean',
'options' => array(),
),
),
'validators' => array(),
'description' => 'Either accumulate the entered quantity to the current basket quantity or set as the entered quantity.',
'allow_empty' => false,
'continue_if_empty' => false,
'error_message' => 'Quantity accumulation field error.',
),
),
When calling the PUT method:
https://cloud.mysite.dev:8890/api/updatecart/1?prod_id=1&quantity=1&update_type=1&tax=0.00
I keep getting Failed Validation errors:
{
"validation_messages": {
"prod_id": [
"Missing product id"
],
"quantity": [
"You must include a quantity"
],
"tax": [
"Please add a tax value, 0.00 for no value."
],
"quantity_accumulation": [
"Quantity accumulation field error."
]
},
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Unprocessable Entity",
"status": 422,
"detail": "Failed Validation"
}
You need to supply your data as http body (payload) in json format.
Make the call to the URI without the query params.
https://cloud.mysite.dev:8890/api/updatecart/1
{
"prod_id": 1,
"quantity": 1,
"update_type": 1,
"tax": "0.00"
}
Also make sure you supply the right request headers:
Accept: application/json
Content-Type: application/json

Append an element to an already existing SOAP::Data complex type

I'm very new to SOAP, PERL and pretty much everything else I've been asked to do so I'm hoping someone can point me in the right direction.
I've implemented a simple WCF solution and I've written a PERL client which passes a "complex data structure" to the solution using SOAP::lite and SOAP::Data. All this works very well so far, WCF solution see's the array as an array and I'm able to iterate through the array on the server side just fine.
However, I'm having an issue trying to append a data element to the array on the PERL side. I have the following code, which builds the array I need, but I need to append a few lines to the array later on in the code and I can't figure out how to that.
# build array of values
my $data= SOAP::Data->new
(name => 'array', value =>
[
SOAP::Data->new(name => 'elem:string', value => 'firststring'),
SOAP::Data->new(name => 'elem:string', value => 'secondstring'),
SOAP::Data->new(name => 'elem:string', value => 'thridstring')
]
)
->attr
(
{ 'xmlns:elem' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays','xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance'}
);
# create a new element
my $elem1 = SOAP::Data->new(name => 'elem:string', value => 'addedstring');
# try to add the element
push(#{$data->{array}},$elem1);
#.... send, catch, print.. bla bla bla
The code I have runs, and the WCF service see's the array just fine, but the $elem1 value is never actually appended to the SOAP envelope.
Any help is GREATLY appreciated...
Take a look at what $data is using Data::Dumper, you get this
$VAR1 = bless( {
'_attr' => {
'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:elem' => 'http://schemas.microsoft.com/2003/10/Serialization/Arrays'
},
'_signature' => [],
'_name' => 'array',
'_value' => [
[
bless( {
'_value' => [
'firststring'
],
'_name' => 'string',
'_prefix' => 'elem',
'_signature' => [],
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_value' => [
'secondstring'
],
'_name' => 'string',
'_signature' => [],
'_prefix' => 'elem',
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_attr' => {},
'_value' => [
'thridstring'
],
'_name' => 'string',
'_signature' => [],
'_prefix' => 'elem'
}, 'SOAP::Data' )
]
]
}, 'SOAP::Data' );
There is no $data->{array}
A look at the documentation for SOAP::Data, says you should use $data->value to access the array you created.
push #{ $data->value }, $elem1;
print Dumper $data->value;
yields
$VAR1 = [
bless( {
'_attr' => {},
'_prefix' => 'elem',
'_value' => [
'firststring'
],
'_name' => 'string',
'_signature' => []
}, 'SOAP::Data' ),
bless( {
'_signature' => [],
'_name' => 'string',
'_value' => [
'secondstring'
],
'_prefix' => 'elem',
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_name' => 'string',
'_signature' => [],
'_value' => [
'thridstring'
],
'_prefix' => 'elem',
'_attr' => {}
}, 'SOAP::Data' ),
bless( {
'_attr' => {},
'_prefix' => 'elem',
'_value' => [
'addedstring'
],
'_name' => 'string',
'_signature' => []
}, 'SOAP::Data' )
];
Thanks Gabs00,
push $data->value, $elem1; worked beautifully

Perl printing second level hash keys in a nested hash

How do I print all my second level hash keys (sig_qtr, date, range, etc.) given a hash like such:
my $xml = XMLin("./${spec_file}", ForceArray => ['range', 'constant', 'question', 'date', 'sig_yr', 'sig_qtr', 'sig_mth'], KeyAttr => {});
print Dumper $xml->{entities};
print dumper output of hash:
$VAR1 = {
'sig_qtr' => [
{
'name' => 'q1',
'label' => 'q1'
},
{
'name' => 'q4',
'label' => 'q4'
}
],
'date' => [
{
'name' => 'y2_mth',
'label' => 'pryr_mth_curr'
},
{
'name' => 'y3_pod6_qtr4',
'label' => 'curr_qtd4'
}
],
'range' => [
{
'name' => 'y0_jun',
'end' => '20100631',
'start' => '20100601'
},
{
'name' => 'y3_oct',
'end' => '20131031',
'start' => '20131001'
}
],
'constant' => [
{
'spec' => '99999999 and 99999999',
'name' => 'none_sixmth'
}
],
'sig_yr' => [
{
'name' => 'y1_sig',
'label' => 'ye11'
},
{
'name' => 'y3_sig',
'label' => 'ytd'
}
],
'sig_mth' => [
{
'name' => 'y3_nov',
'label' => 'nov12'
},
{
'name' => 'y3_oct',
'label' => 'oct13'
}
],
'question' => [
{
'name' => 'ltrq',
'label' => 'q9'
},
{
'name' => 'nextprod',
'label' => 'q12a'
}
],
'backfill' => {
'label' => 'bf_period'
},
'year' => {
'current' => '2013'
}
};
would be even better if keys are put into an array.
Thanks.
print "$_\n" for keys %{ $xml->entities };
To put them into an array,
my #keys = keys %{ $xml->entities };