Receipt_id is null in Paypal response, How can I get it? - ruby-on-rails-4

I have integrated Paypal with my rails application by activemerchant gem, As of now I'm getting token and payer_id, but I need receipt_id which is null in response.
I have followed steps given in this link.
Response of Paypal is given below
"timestamp"=>"2016-04-12T19:23:46Z", "ack"=>"Success",
"correlation_id"=>"000a000f000r", "version"=>"124", "build"=>"000000",
"token"=>"AB-000000000000000", "transaction_id"=>"kjKJKHkj09809FED2",
"parent_transaction_id"=>NULL, "receipt_id"=>NULL,
"transaction_type"=>"express-checkout", "payment_type"=>"instant",
"payment_date"=>"2016-04-12T19:23:46Z", "gross_amount"=>"160.00",
"gross_amount_currency_id"=>"USD", "fee_amount"=>"6.54",
"fee_amount_currency_id"=>"USD", "tax_amount"=>"0.00",
"tax_amount_currency_id"=>"USD", "exchange_rate"=>NULL,
"payment_status"=>"Completed", "pending_reason"=>"none",
"reason_code"=>"none", "protection_eligibility"=>"Eligible",
"protection_eligibility_type"=>"ItemNotReceivedEligible,UnauthorizedPaymentEligible",
"secure_merchant_account_id"=>"JHBJKJKJBKJBKJH",
"success_page_redirect_requested"=>"false",
"coupled_payment_info"=>NULL, "Token"=>"AB-000000000000000",
"PaymentInfo"=>"{"TransactionID"=>"kjKJKHkj09809FED2",
"ParentTransactionID"=>nil, "ReceiptID"=>nil,
"TransactionType"=>"express-checkout", "PaymentType"=>"instant",
"PaymentDate"=>"2016-04-12T19:23:46Z", "GrossAmount"=>"160.00",
"FeeAmount"=>"6.54", "TaxAmount"=>"0.00", "ExchangeRate"=>nil,
"PaymentStatus"=>"Completed", "PendingReason"=>"none",
"ReasonCode"=>"none", "ProtectionEligibility"=>"Eligible",
"ProtectionEligibilityType"=>"ItemNotReceivedEligible,UnauthorizedPaymentEligible",
"SellerDetails"=>{"SecureMerchantAccountID"=>"JHBJKJKJBKJBKJH"}}",
"SuccessPageRedirectRequested"=>"false", "CoupledPaymentInfo"=>NULL
Is there any configuration in Paypal account to get receipt_id, or any request parameter I have to add/change?
Please suggest.
Thanks in advance.

I have discussed this with paypal developer support and it seems like the transaction sale ID is the appropriate ID to record and return to the user, it is also what gets recorded in the paypal account for a credit card transaction so if a user had a support question, it is the easiest number to give to accounts to look up the transaction details.
I am not 100% sure about how to access what is called the receipt_id, but I don't think it is intended to be populated in the response to the payment endpoint. If you are to get a receipt_id at all, it will likely come from hitting the endpoint GET /v1/payments/sale/<Transaction-Id>
As per the api, receipt_id is defined as
Receipt id is 16 digit number payment identification number returned for guest users to identify the payment.
I think "guest users" may have a specific meaning that is not relevant to just any transaction but I'm not positive on this.
I would recommend playing around with this endpoint after you get the transaction ID from the payments endpoint. The id located in the json returned from the payments endpoint at payment.transactions[0].related_resources[0].sale.id seemed to be the appropriate ID to record for a simple credit card transaction where I wanted to return a reference number to the client and to store for looking up the transaction at a later date.
I also was able to use that ID to interrogate the sale endpoint mentioned above for more information, but I never was able to get receipt_id to populate for a sandbox operation.
Hope this helps, I find some of the documentation to be lacking for the REST api.
"transactions": [
{
"amount": {
"total": "7.47",
"currency": "USD",
"details": {
"tax": "0.03",
"shipping": "0.03"
}
},
"description": "This is the payment transaction description.",
"related_resources": [
{
"sale": {
"id": "4RR959492F879224U",
"create_time": "2013-01-31T04:12:02Z",
"update_time": "2013-01-31T04:12:04Z",

Related

GMB MyBusiness API - How to set up real-time PubSub notifications?

I am working on integrating GMB into some of our internal apps, and would like to set up to receive real-time notifications for reviews and questions.
I have created a topic, and a subscription with a valid URL.
The next step is to tell GMB to send the notifications to the topic, and I believe the endpoint is the one below. However, it is very vague about the parameters it wants.
This is the documentation
https://developers.google.com/my-business/reference/rest/v4/accounts/updateNotifications
It wants a "Notification Settings Resource Name" in the URL, but it's not explained anywhere what that actually is. I have tried every possible value, but always get a 404 error response with the message "Requested entity was not found."
Has anyone successfully set this up? What values does the "getNotifications" endpoint want, and where in the various dashboards can this be found or created?
Any help is much appreciated!
As mentioned in the comments, you need to send the accountId as part of the URL.
To find this, you will first need to send a GET request to
https://mybusiness.googleapis.com/v4/accounts
This will return something along the following lines:
{
"accounts": [
{
"name": "accounts/102647145453118950380",
"accountName": "Tom Spencer",
"type": "PERSONAL",
"state": {
"status": "UNVERIFIED",
"vettedStatus": "NOT_VETTED"
},
"profilePhotoUrl": "//lh3.googleusercontent.com/a-/AOh14GgPkuJj03DeCa1isBAJALY4eOl09WGYVFrM4mG5=s132"
},
]
}
You can see here that accounts/102647145453118950380 is returned in the name field. Take this field, and construct the following URL:
https://mybusiness.googleapis.com/v4/accounts/102647145453118950380/notifications
Send a PUT request to this URL, with a request body resembling the following:
{
"topicName": "projects/{projectId}/topics/{topicId}",
"notificationTypes": [
"NEW_REVIEW",
"UPDATED_REVIEW"
]
}
Assuming you have pub/sub setup as per the documentation, this should send a message to your topic/subscribers whenever a new review is created or a review is updated.

Instagram Graph API - Fetch media insights metric when a user switched from personal to business account

I'm looking for a way to fetch Media Insights metrics in Instagram Graph API (https://developers.facebook.com/docs/instagram-api/reference/media/insights) with a nested query based on the userId, even when a client switched from a Personal to a Business account.
I use this nested query to fetch all the data I need : https://graph.facebook.com/v3.2/{userId}?fields=followers_count,media{media_type,caption,timestamp,like_count,insights.metric(reach, impressions)} (this part causes the error: insights.metric(reach, impressions) - it works however for an account that has always been a Business one)
However, because some media linked to the userId were posted before the user switched to a Business account, instead of returning the data only for the media posted after, the API returns this error:
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": {
"blame_field_specs": [
[
""
]
]
},
"error_subcode": 2108006,
"is_transient": false,
"error_user_title": "Media Posted Before Business Account Conversion",
"error_user_msg": "The media was posted before the most recent time that the user's account was converted to a business account from a personal account.",
"fbtrace_id": "Gs85pUz14JC"
}
}
Is there a way to know, thru the API, which media were created before and after the account switch from Personal to Business? Or is there a way to fetch the date on which the account was switched?
The only way I currently see to get the data I need is to use the /media edge and query insights for each media until I get an error. Then I would get approximately the date I need. However, this is not optimized at all since we are rate limited to 200 calls per user per hour.
I have the same problem.
For now, I'm Switch between queries (if first have error)
"userId"?fields=id,media.limit(100){insights.metric(reach, impressions)}
"userId"?fields=id,media.limit(100)
I show the user all insights in zero.
I don't know if they're the best alternative, like identify the time of conversion to business and get the post between this range of DateTime
I got the same problem and solved it like this:
Use the nested query just like you did, including insights.metric
If the error appears, do another call without insights.metric - to at least get all other data
For most accounts, it works and there is no additional API call. For the rest, i just cannot get the insights and i have to live with it, i guess - until Facebook/IG fixes the issue.
I got the same problem and solved it like this:
Step1: Convert your Instagram account to a Professional account.
Step2: Then According to Error Post a new post on Instagram and get their Post-ID.
Step3: Then try to get a request using that Post-ID.
{Post-ID}?fields=comments_count,like_count,timestamp,insights.metric(reach,impressions)
curl -i -X GET "https://graph.facebook.com/v12.0/{Post-ID}?fields=comments_count%2Clike_count%2Ctimestamp%2Cinsights.metric(reach%2Cimpressions)&access_token={access_token}"
For more: insights
Here is the relevant logic from a script that can handle this error while still doing a full import. It works by reducing the requested limit to 1 once the error is encountered. It will keep requesting insights until it encounters the error again, then removes insights from the fields and returns to the requested limit.
limit = 50
error_2108006 = False
metrics = 'insights.metric%28impressions%29%2C' # Must be URL encoded for replacement
url = '/PAGE_ID/media?fields=%sid,caption,media_url,media_type&limit=%s' % (metrics, limit)
# While we have more pages
while True:
# Make your API call to Instagram
posts = get_posts_from_instagram(url)
# Check for error 2108006
if posts == 2108006:
# First time getting this error, keep trying to get insights but one by one
if error_2108006 is False:
error_2108006 = True
url = url.replace('limit={}'.format(limit), 'limit=1')
continue
# Not the first time. Strip out insights and return to desired limit.
url = url.replace(metrics, '')
url = url.replace('limit=1', 'limit='.format(limit))
continue
# Do something with the data
for post in posts:
continue
# If there are more pages, fetch the next URL
if 'paging' in posts and 'next' in posts['paging']:
url = posts['paging']['next']
continue
# Done
break

Directory API, User organizations- name field. Where does it come from?

The Google Directory API https://developers.google.com/admin-sdk/directory/v1/reference/users/get
returns following kind of organizations data for a User. However in the Apps Admin console I can not find where the corresponding organisations name "Company Title" is defined. From where does it come from or how to edit that data? This is also inconsistent, since for some Users in this same domain the "name" field is missing completely?
"organizations": [
{
"name": "Company Title",
"title": "Software Developer",
"primary": true,
"type": "work",
"department": "The SW department"
}
],
I'm not particular about the Apps Admin console but you can update a user account if there are data that has to be changed.
To update a user account, use the following PUT request and include the authorization described in Authorize requests. The userKey can be the user's primary email address, the unique user id, or one of the user's alias email addresses. For the request and response properties, see the API Reference.
PUT https://www.googleapis.com/admin/directory/v1/users/userKey
You can try the REST API to retrieve all or children organization units.
To retrieve all sub-organization units under an organization unit or to retrieve the immediate children sub-organization units under an organization unit, use the following GET request and include the authorization described in Authorize requests. For the request and response properties, see the API Reference.
GET https://www.googleapis.com/admin/directory/v1/customer/my_customer
/orgunits?orgUnitPath=full org unit path&type=all or children
Here is a sample response to the List of Org unit/s
{
"kind": "directory#orgUnit",
"name": "sales",
"description": "The corporate sales team",
"orgUnitPath": "/corp/sales",
"parentOrgUnitPath": "/corp",
"blockInheritance": false
}
You can also try using the Update an organization unit:
To update an organization unit, use the following PUT request and include the authorization described in Authorize requests. For the request and response properties, see the API Reference:
PUT https://www.googleapis.com/admin/directory/v1/customer/customerId/orgunits/orgUnitPath
You can compare the values in the REST API and Admin Console.
Hope it helps!

facebook graph API company page URL?

I am working on some data analysis regarding beverage manufacturers in the US and would like to grab posts from the company facebook pages to mine some data using the standard facebook graph API. I am new to the facebook API and I am hoping to get some clarifications here that I can't find in the developer docs.
For a simple example lets look at 2 companies FB pages:
https://www.facebook.com/CocaColaUnitedStates
https://www.facebook.com/BellsBreweryInc
Now per the API documentation, I should be able to retrieve the posts on those public company pages via a URL as follows:
https://graph.facebook.com/COMPANYFBNAMEHERE/feed?access_token=MYTOKEN
or
https://graph.facebook.com/v2.5/COMPANYFBNAMEHERE/feed?access_token=MYTOKEN
This works for CocaCola: https://graph.facebook.com/v2.5/CocaColaUnitedStates/feed?access_token=MYTOKEN
This returns data as I would expect:
{
"data": [
{
"message": "The French \"yes! yes! yes!\" sounds like \"we! we! we!\" (lettered \"oui.\") \"C'est la vie\" sounds like (homonym) \"say LOVIE\" (like lovie dovie).\n\nSong of (rather than \"by\") Robbie Nevil: C'est La Vie\nhttp://www.youtube.com/watch?v=CGtf9QfITQw",
"created_time": "2016-02-06T02:52:17+0000",
"id": "820882001277849_452698638250376"
},
etc....
However when I try this for Bell's: https://graph.facebook.com/v2.5/BellsBreweryInc/feed?access_token=MYTOKEN
I get this:
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "AWTxWye6vub"
}
}
I am not understanding why I am getting an error on Bell's page? It's a publicly available company FB page, so I can't imagine it's a restriction, but I can't understand why it wouldn't be returning the posts like CocaCola?
It sounds like the owner of the token you are using is below the legal drinking age. BellsBreweryInc is a page in the alcohol category so no data will be returned for users under the legal age. This is something BellsBreweryInc would have set in their page settings.
Age restircted websites require a user access token from a user account that meets the page requirements. I was using an app access token which is why it didn't work.
I needed to log into my account and generate a user access token and use that token in the URL.
Also, just realized that token expires in a couple hours. Anyone wanting to do this may also want to read this: How to extend facebook access token in python

Facebook API: Error "(#210) Subject must be a page" when posting a Status Update on a Page

I want to post a simple status update on one of my pages with a perl-script. To find out how to do best, I use facebooks Graph API Explorer https://developers.facebook.com/tools/explorer for experiments
I use the access token of my FB-app. This app is doing a good job since 2 years. The access token will expire in about 2 month and among many other permissions it has the permissions "publish_stream" and "manage_pages".
I select "POST", then, in the field next to "POST", I enter the ID of my page (a 15-digit-number starting with 102 ending with 937). This ID is correct, because I can GET data from this page using exactly this ID.
I click on "Add a field", then I enter the field-name "message" and the value "test-message". Then I click on "Submit". And then I get this result:
{
"error": {
"message": "(#210) Subject must be a page.",
"type": "OAuthException",
"code": 210
}
}
But posting a comment to an existing posting on the same page works fine. I simply replace the page-ID 102...937 with 501...852/comments where "102...937" and "501...852" are 15-digit-numbers.
What am I doing wrong? What must I do to post a message on my page using the Graph API Explorer? "102...937" is the ID of an existing page. I am managing 3 pages, I have the same problem with all 3 IDs.
I found the solution:
In the field next to POST I only did enter the Page-ID (like 123456789012345) but you must add "/feed" to the end, like this: 123456789012345/feed
The documentation does not say how to post a status message. To me it was clear, If want to post something on a page, I have to enter the pages ID, not more. And if the error-message would have said "Subject must be a FEED" everything would have been clear. But is said "must be a PAGE" but it already was a page.