get currency-converted amount via REST API - paypal

We currently process USD payments via paypal's REST API using their ruby gem. I would like to accept other currencies and have set our account to auto-convert foreign currency payments to USD. I can successfully process these payments and can see in the sandbox web interface that they were converted, but it's unclear to me how to look the conversion transactions up via the API. Can anyone shed any light on this? See screenshot and completed payment + sale record below.
Response[200]: OK, Duration: 0.858s
{
"id" => "PAY-0XK33729VB648561PKV5SG6A",
"intent" => "sale",
"payer" => {
"payment_method" => "paypal",
"status" => "VERIFIED",
"payer_info" => {
"email" => "jack#example.com",
"first_name" => "Fake",
"last_name" => "Fakerson",
"payer_id" => "F2JC8YDQ6HDUA",
"shipping_address" => {
"line1" => "1 Main St",
"city" => "San Jose",
"state" => "CA",
"postal_code" => "95131",
"country_code" => "US",
"recipient_name" => "Fake Fakerson"
}
}
},
"transactions" => [
[0] {
"amount" => {
"currency" => "EUR",
"total" => "5.00",
"details" => {
"subtotal" => "5.00"
}
},
"description" => "Unlimited School - I'm a course",
"related_resources" => [
[0] {
"sale" => {
"id" => "24439073LW446012K",
"amount" => {
"currency" => "EUR",
"total" => "5.00"
},
"payment_mode" => "INSTANT_TRANSFER",
"state" => "completed",
"protection_eligibility" => "ELIGIBLE",
"protection_eligibility_type" => "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee" => {
"currency" => "EUR",
"value" => "0.50"
},
"parent_payment" => "PAY-0XK33729VB648561PKV5SG6A",
"create_time" => "2015-06-12T18:22:48Z",
"update_time" => "2015-06-12T18:23:19Z",
"links" => [
[0] {
"href" => "https://api.sandbox.paypal.com/v1/payments/sale/24439073LW446012K",
"rel" => "self",
"method" => "GET"
},
[1] {
"href" => "https://api.sandbox.paypal.com/v1/payments/sale/24439073LW446012K/refund",
"rel" => "refund",
"method" => "POST"
},
[2] {
"href" => "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0XK33729VB648561PKV5SG6A",
"rel" => "parent_payment",
"method" => "GET"
}
]
}
}
]
}
],
"state" => "approved",
"create_time" => "2015-06-12T18:22:48Z",
"update_time" => "2015-06-12T18:23:19Z",
"links" => [
[0] {
"href" => "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0XK33729VB648561PKV5SG6A",
"rel" => "self",
"method" => "GET"
}
]
}

I don't think so that REST API has any API for fetching the currency conversion only at this moment .
However , you can use the PayPal's Classic API to achieve your goal . See the example below :
NVP Request:
USER=XXXX&PWD=XXXXX&SIGNATURE=XXXXXXXX&VERSION=109.0&METHOD=TransactionSearch&STARTDATE=2014-06-01T00:00:00Z&ENDDATE=2015-06-05T00:00:00Z&TRANSACTIONCLASS=CurrencyConversions
NVP Response:
L_TIMESTAMP0=2015-04-21T20:53:39Z
L_TIMESTAMP1=2015-04-21T20:53:39Z
L_TIMESTAMP2=2014-11-11T18:40:45Z
L_TIMESTAMP3=2014-11-11T18:40:45Z
L_TIMEZONE0=GMT
L_TIMEZONE1=GMT
L_TIMEZONE2=GMT
L_TIMEZONE3=GMT
L_TYPE0=Currency Conversion (credit)
L_TYPE1=Currency Conversion (debit)
L_TYPE2=Currency Conversion (credit)
L_TYPE3=Currency Conversion (debit)
L_NAME0=From British Pound
L_NAME1=To U.S. Dollar
L_NAME2=From U.S. Dollar
L_NAME3=To British Pound
L_TRANSACTIONID0=76K70596XX6169325
L_TRANSACTIONID1=7P3811819E363281J
L_TRANSACTIONID2=2GF65791PP4273901
L_TRANSACTIONID3=2K135972TE2156124
L_STATUS0=Completed
L_STATUS1=Completed
L_STATUS2=Completed
L_STATUS3=Completed
L_AMT0=4060.54
L_AMT1=-2626.32
L_AMT2=6.36
L_AMT3=-10.36
L_CURRENCYCODE0=USD
L_CURRENCYCODE1=GBP
L_CURRENCYCODE2=GBP
L_CURRENCYCODE3=USD
L_FEEAMT0=0.00
L_FEEAMT1=0.00
L_FEEAMT2=0.00
L_FEEAMT3=0.00
L_NETAMT0=4060.54
L_NETAMT1=-2626.32
L_NETAMT2=6.36
L_NETAMT3=-10.36
TIMESTAMP=2015-06-12T22:48:14Z
CORRELATIONID=f01a7f7fb27f2
ACK=Success
VERSION=109.0
BUILD=16964802

Related

How to add regex validator in form class in zend

I have a User form class which has elements and I am trying to add Regex validator.
Here is what I have tried
$inputFilter->add([
"name" => "password",
"required" => true,
"filters" => [
],
"validators" => [
[
"name" => new Regex(["pattern" => "/^[a-zA-Z0-9_]+$/"]),
],
[
"name" => "NotEmpty",
],
[
"name" => "StringLength",
"options" => [
"min" => 6,
"max" => 64
],
],
],
]);
But it throws
Object of class Zend\Validator\Regex could not be converted to string
Can anyone help me out?
You can add input filter specifications for the validator, the following should work
$inputFilter->add([
"name" => "password",
"required" => true,
"filters" => [
],
"validators" => [
// add validator(s) using input filter specs
[
"name" => "Regex",
"options" => [
"pattern" => "/^[a-zA-Z0-9_]+$/"
],
],
[
"name" => "NotEmpty",
],
[
"name" => "StringLength",
"options" => [
"min" => 6,
"max" => 64
],
],
],
]);
If you really want to instantiate the object (using the new Regex(...) as in your original code), you can do that this way instead
$inputFilter->add([
"name" => "password",
"required" => true,
"filters" => [
],
"validators" => [
// add a regex validator instance
new Regex(["pattern" => "/^[a-zA-Z0-9_]+$/"]),
// add using input filter specs ...
[
"name" => "NotEmpty",
],
[
"name" => "StringLength",
"options" => [
"min" => 6,
"max" => 64
],
],
],
]);
You may also find this zf blog post useful Validate data using zend-inputfilter, as well as the official zend-input-filter docs

What is the correct format for creating the creative of an MPA Advertisement on facebook?

I've been trying to create a MPA(multi-product ad) for some time now, but it keeps giving me the following error "Call to action link should be same as link of the post".
I've used the following format:
{
"object_story_spec" => {
"page_id" => 321954304600161,
"instagram_actor_id" => "874410812666052",
"link_data" => {
"multi_share_optimized" => true,
"multi_share_end_card" => true,
"message" => "Test message ad in adset",
"caption" => nil,
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=TestforJson-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_testadinadset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92",
"child_attachments" => [{
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=Test for Json-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_test ad in adset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92",
"name" => "TEst ad in adset",
"description" => nil,
"picture" => "https://adcreation-m.s3-ap-south-1.amazonaws.com/1512559029_test.jpg",
"call_to_action" => {
"type" => "SHOP_NOW",
"value" => {
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=TestforJson-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_testadinadset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92"
}
}
}, {
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=Test for Json-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_test ad in adset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92",
"name" => "TEst",
"description" => nil,
"picture" => "https://adcreation-m.s3-ap-south-1.amazonaws.com/1512559033_test.jpg",
"call_to_action" => {
"type" => "SHOP_NOW",
"value" => {
"link" => "http://www.adwyze.com?utm_source=facebook&utm_medium=ocpm&utm_campaign=TestforJson-06Dec2017-16h48m&utm_term=all-MF-18-65-06Dec2017-16h48m&utm_content=test_testadinadset-00-CarouselAd-06Dec2017-19h44m&utm_id=2b301660-01c2-4c21-9fe1-06863dbaac92"
}
}
}]
}
}
}
I've made sure that in "child_attachments". "link" and "call_to_action.value.link" have the same value, but I keep getting the same error. I've also tried escaping the links, removing spaces etc. I've been seeing this behaviour since 10 hours or so.
Despite's OP incorrect link values in the child_attachment and call_to_action, this has been confirmed by Facebook as a valid bug:
https://developers.facebook.com/bugs/310154929502029/
https://developers.facebook.com/bugs/1909897769263210/
I'm guessing OP was testing a lot of different combinations and this one he posted happened to have different values.
Hopefully this will be fixed soon.

How do I use map to merge an array of hashes?

Hoping someone could explain the proper process for this. I have a data structure like this:
[
{
Author => "101",
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "",
WK13 => "",
WK14 => "X",
WK15 => "",
},
{
Author => "102",
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "X",
WK13 => "X",
WK14 => "",
WK15 => "",
WK2 => "X",
WK3 => "X",
WK4 => "",
},
{
Author => "101",
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "",
WK13 => "",
WK14 => "X",
WK15 => "X",
},
]
WK keys may or may not exist. The Author key will always exist, and I’m trying to merge those duplicates. Overwriting values is ok (if defined).
Should I try map (not sure how), or would it be better to create a new hash using the Author as key, pushing the other values into an array? Something like
foreach $x (#$data) {
%new_hash = ...
...
}
scratching head
It sounds like you are starting with something like the following:
my $records = [
{ Author => "101", WK1 => "", WK2 => "X", WK3 => "X" },
{ Author => "101", WK1 => "X", WK2 => "", WK4 => "X" },
{ Author => "102", WK1 => "", WK2 => "", WK3 => "X" },
];
It sounds like you want to produce the following:
my $records_by_author = (
"101" => { Author => "101", WK1 => "X", WK2 => "", WK3 => "X", WK4 => "X" },
"102" => { Author => "102", WK1 => "", WK2 => "", WK3 => "X" },
);
The following will do that:
my %records_by_author;
for my $record (#$records) {
my $author = $record->{Author};
$records_by_author{$author} = {
( $records_by_author{$author} ? %{ $records_by_author{$author} } : () ),
%$record,
};
}
If instead you want the following output:
my $records = [
{ Author => "101", WK1 => "X", WK2 => "", WK3 => "X", WK4 => "X" },
{ Author => "102", WK1 => "", WK2 => "", WK3 => "X" },
];
Just add the following:
$records = [ values(%records_by_author) ];
It you want this output and you want to preserve the original order, let me know.
I suggest merging along the lines of the code below. From each anonymous hash in #$data, grab the author identifier and then update the merged WK values where we never overwrite a non-empty string with an empty one.
You could do the same with map, and that would be a worthwhile exercise. It seems to read much more naturally as nested structural loops.
my %authorwk;
for (my $i = 0; #$data; ++$i) {
local $_ = shift #$data;
die "$0: missing Author in record $i" unless exists $_->{Author};
my $author = $_->{Author};
while (my($wk,$present) = each %$_) {
next unless $wk =~ /^WK/;
$authorwk{$author}{$wk} = $present
if $present || !exists $authorwk{$author}{$wk};
}
}
map is inappropriate here: a series of slice assignments is all that is necessary
It looks like this. Note that the only duplicate author 101 has an identical set of keys in both instances, so I've added key WK7 to the first instance and WK8 to the second so that you can see that they are both added to the result
use strict;
use warnings 'all';
my $data = [
{
Author => 101,
WK7 => "7", WK1 => "", WK10 => "", WK11 => "",
WK12 => "", WK13 => "", WK14 => "X", WK15 => "",
},
{
Author => 102,
WK1 => "", WK10 => "", WK11 => "", WK12 => "X",
WK13 => "X", WK14 => "", WK15 => "", WK2 => "X",
WK3 => "X", WK4 => "",
},
{
Author => 101,
WK8 => "8", WK1 => "", WK10 => "", WK11 => "",
WK12 => "", WK13 => "", WK14 => "X", WK15 => "X",
},
];
my %authors;
for my $item ( #$data ) {
my $author = $item->{Author};
#{ $authors{$author} }{keys %$item} = values %$item;
}
use Data::Dump;
dd \%authors;
output
{
101 => {
Author => 101,
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "",
WK13 => "",
WK14 => "X",
WK15 => "X",
WK7 => 7,
WK8 => 8,
},
102 => {
Author => 102,
WK1 => "",
WK10 => "",
WK11 => "",
WK12 => "X",
WK13 => "X",
WK14 => "",
WK15 => "",
WK2 => "X",
WK3 => "X",
WK4 => "",
},
}

Email, gender, age not returned with Omniauth and facebook API 2.4

I could NOT get back the email information anymore with Omniauth.
I think the problem is duing to the API 2.4,
But I don't get how could I the the expected information
Devise config
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {
:scope => 'email',
:info_fields => 'id,email,gender,link,locale,name,timezone,updated_time,verified',
strategy_class: OmniAuth::Strategies::Facebook,
:provider_ignores_state => true}
Returned information not including email information
:1> env['omniauth.auth']
{
"provider" => "facebook",
"uid" => "xxxx",
"info" => {
"name" => "Eric Hsu",
"image" => "http://graph.facebook.com/xxxx/picture?type=square"
},
"credentials" => {
"token" => "CAAh",
"expires_at" => 1443066205,
"expires" => true
},
"extra" => {
"raw_info" => {
"name" => "Eric Hsu",
"id" => "xxxx"
}
}
}
I found the problem is that the dependency between FB API and omniauth-facebook version.
current i installed the gem omniauth-facebook (2.0.1)

How can i update the ids field?

Unfortunately, I cannot use positional operators since there is a bug that doesn't allow deeper than 1 embedded document: https://jira.mongodb.org/browse/SERVER-831
So this wont work (using the Mongodb Ruby driver):
stat_profile.update({ profile_id: profile.id, providers: { '$elemMatch' => { provider_name: 'foo', dates: { '$elemMatch' => { date: 20130911, relationships: { '$elemMatch' => { relationship_type: 'friend' } } } } } } },
{ '$set' => { 'providers.$.dates.$.relationships.$.ids' => [1,2,3] } })
Given the following collection. Relationships is embedded in dates, dates is embedded in providers.
How do I update the ids field?
{
"_id" => BSON::ObjectId('523048983858f61767000008'),
"profile_id" => 3,
"providers" => [
[0] {
"provider_name" => "foo",
"dates" => [
[0] {
"date" => 20130911,
"relationships" => [
[0] {
"relationship_type" => "acquaintance",
"count" => 0
},
[1] {
"relationship_type" => "friend",
"count" => 0,
"males_count" => 0,
"females_count" => 0,
"top_ten_countries" => [],
"ids" => []
}
]
}
]
}
]
}