Accept payment via the Shopify API - shopify

In the Shopify admin area there is a button on each order to "Accept Payment". Is there an equivalent action that can be performed via the API?

Yes. You can create a transaction and capture the amount that was previously authorized.
ShopifyAPI::Transaction.create({:order_id => order.id, :kind => 'capture'})

Yes, make sure the original order is created through the API and has a status of "pending", transaction kind of "authorization", and transaction status of "success". Then when you capture the payment it is only changing the financial status. You cannot just change the financial status value on the order without capturing the transaction.
So this is the original request to create the order using the API:
POST /admin/orders.json
{
"financial_status": "pending",
"fulfillment_status": "fulfilled",
"transactions": [{
"amount": "21",
"kind": "authorization",
"gateway": "Gateway",
"status": "success",
"source_name": "My API"
}]
}
And then to capture the transaction do this:
POST /admin/orders/{order_id}/transactions.json
{
"transaction": {
"kind": "capture"
}
}
Make sure you have write permissions enabled for orders on your API:
https://redeeem.myshopify.com/admin/apps/private

Related

403 Error creating dataSource for com.google.blood_pressure in Google Fit REST API

Goal:
I have a simple web application where I submit my Blood Pressure and Heart Rate measurements.
Now I'd like to submit these measurements to my Google Fit Account.
I tried Googles tutorial: https://developers.google.com/fit/scenarios/write-bp-data
OAuth2 Setup
I created new credentials in one of my existing Cloud Console Projects. And then requested a new authorization code using the following scopes (The project is in Testing State and my account is registered as tester):
https://www.googleapis.com/auth/fitness.blood_pressure.write
https://www.googleapis.com/auth/fitness.heart_rate.write
Requesting the token returns the following response:
{
"access_token": "ya29.XXXXXXXXXXXXXXXX",
"expires_in": 3599,
"refresh_token": "1//XXXXXXXXXXXXXXXX",
"scope": "https://www.googleapis.com/auth/fitness.heart_rate.write https://www.googleapis.com/auth/fitness.blood_pressure.write",
"token_type": "Bearer"
}
As you can see, both write scopes are granted.
Additionally, if I check the permissions in my Google Account, both scopes are set.
Create dataSource
Now I create two dataSources (one for com.google.heart_rate.bpm and one for com.google.blood_pressure).
creating the Heart Rate dataSource works as expected, but creating a dataSource for Blood Pressure returns a 403 PERMISSION_DENIED Error:
Request (POST https://www.googleapis.com/fitness/v1/users/me/dataSources)
{
"dataStreamName": "BPA-BloodPressure",
"type": "raw",
"application": {
"detailsUrl": "https://aaa.bbb.ccc",
"name": "Blood Pressure App",
"version": "1"
},
"dataType": {
"name": "com.google.blood_pressure"
}
}
Response
{
"error": {
"code": 403,
"message": "Scope not included to modify data of type com.google.blood_pressure. Possible scopes: https://www.googleapis.com/auth/fitness.blood_pressure.write",
"errors": [
{
"message": "Scope not included to modify data of type com.google.blood_pressure. Possible scopes: https://www.googleapis.com/auth/fitness.blood_pressure.write",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
The Google Fit REST API tells me that the Scope fitness.blood_pressure.write is missing, but as you can see the Scope is given for the used access token.
Notes
I am working with Postman to test all requests. Later a Java/Groovy or PHP backend will used.
I also tried with read and write scopes for both data types.
I can see my app with both write scopes in Google Fit under "Connected apps".
Change dataType name to "fitness.blood_pressure" instead of "com.google.blood_pressure"
The body will be like this.
{
"dataStreamName": "BPA-BloodPressure",
"type": "raw",
"application": {
"detailsUrl": "https://aaa.bbb.ccc",
"name": "Blood Pressure App",
"version": "1"
},
"dataType": {
"name": "fitness.blood_pressure"
}
}

How to know the Shopify username who triggered a webhook?

I have a product/update Shopify webhook. When the webhook event comes, I see the JSON payload but I don't get any clue about who updated the product. I need the username or email or whatever to identify the user who triggered the webhook. Is that even possible ? If yes, how ?
As per Shopify Documentation, product/update hook does not contain any information regarding the user who triggered the action. However, if it is extremely important for you to find out the user, a workaround is to use the Shopify Events API. As you already have the Product ID in the recieved webhook, you may issue another call to
GET /admin/products/#{product_id}/events.json
and in the response
{
"events": [
{
"id": 677313116,
"subject_id": 921728736,
"created_at": "2008-01-10T08:00:00-05:00",
"subject_type": "Product",
"verb": "create",
"arguments": [
"IPod Touch 8GB"
],
"body": null,
"message": "Product was created: IPod Touch 8GB.",
"author": "Shopify",
"description": "Product was created: IPod Touch 8GB.",
"path": "/admin/products/921728736"
}
]
}
you will have the author field. You may further filter the result using verb and created_at fields.
The supported events are
But I am also only able to get the created, published and unpublished events.

Square REST API: Error issuing refund

Every time I try to refund a card, I get the JSON pasted below. This happens after I authorize a card, then capture the charge, then want to issue a partial refund. For “tender_id” I have tried both the transaction ID and the ID I am handed during the authorization. Of course for the capture there is no tender_id or id because a successful capture returns just “{}”.
I am also using sandbox credentials. The charge was done with a nonce generated with sandbox credentials as well.
What’s wrong?
Thanks...
POST to:
https://connect.squareup.com/v2/locations/CBASEHHNorL75TjuSOAvKQLnuNYgAQ/transactions/a2905f34-c8e8-5534-7676-82e8c580e9bf/refund
With this JSON:
{
"idempotency_key":"6464dc19-1703-47c0-81f9-4f0f1361eada",
"tender_id":"291d56b3-1e73-5bff-6e8e-719fd134b83f",
"reason":”Partial refund",
"amount_money":{
"amount":4500,
"currency":"USD"
}
}
Gives this reply:
{
"errors": [
{
"category": "INVALID_REQUEST_ERROR",
"code": "NOT_FOUND",
"detail": "Location `CBASEHHNorL75TjuSOAvKQLnuNYgAQ` does not have a transaction tender with ID `291d56b3-1e73-5bff-6e8e-719fd134b83f`."
}
]
}
UPDATE: The result from the requested GET call (in the comments to the answer) is:
{
"transaction":{
"id":"a2905f34-c8e8-5534-7676-82e8c580e9bf",
"location_id":"CBASEHHNorL75TjuSOAvKQLnuNYgAQ",
"created_at":"2017-02-21T22:08:10Z",
"tenders":[
{
"id":"a18b98c7-5ac7-51c1-618c-3b95ee124c1b",
"location_id":"CBASEHHNorL75TjuSOAvKQLnuNYgAQ",
"transaction_id":"a2905f34-c8e8-5534-7676-82e8c580e9bf",
"created_at":"2017-02-21T22:08:10Z",
"note":"Online Transaction",
"amount_money":{
"amount":12500,
"currency":"USD"
},
"processing_fee_money":{
"amount":372,
"currency":"USD"
},
"type":"CARD",
"card_details":{
"status":"CAPTURED",
"card":{
"card_brand":"VISA",
"last_4":"5858"
},
"entry_method":"KEYED"
}
}
],
"reference_id":"63614ae8-539a-4339-b5c7-554bae64fbed",
"product":"EXTERNAL_API"
}
}
After you capture, have you tried listing/retrieving the transaction to get the full details, including tender ids? Could you post your response from GET /v2/locations/CBASEHHNorL75TjuSOAvKQLnuNYgAQ/transactions/a2905f34-c8e8-5534-7676-82e8c580e9bf if that doesn't work?

Yodlee AddSiteAccount1 issues

I am trying to verify various MFA based accounts Yodlee API by performing following steps:
Successful call to addSiteAccount1
In response, it does return siteAccountId
In response, it also provides site refresh status that REFRESH_TRIGGERED
if resp['siteRefreshInfo']['siteRefreshMode']['refreshMode'] == 'MFA' and
resp['siteRefreshInfo']['isMFAInputRequired'] == True and
resp['siteRefreshInfo']['siteRefreshStatus']['siteRefreshStatus'] ==
'REFRESH_TRIGGERED'
Now, calling getMFAResponseForSite repeatedly together with getSiteRefreshInfo results into initially code 801 and than 508 eventually timeout.
Eventually, I come out of the loop with result isMessageAvailable: True
{u'itemId': 0,
u'retry': False, u'timeOutTime': 99880, u'memSiteAccId': 10144098,
u'errorCode': 0, u'isMessageAvailable': True, u'fieldInfo':
{u'questionAndAnswerValues': [], u'numOfMandatoryQuestions': -1,
u'mfaFieldInfoType': u'SECURITY_QUESTION'}}
The only concern I have is that it provides mfaFieldInfoType, but it doesn't provide the actual question.
Couple questions:
a. How do I retrieve proper MFA question(s) for the site?
b. If user is initially coming into system and would like to link account more than couple second wait for user will kill the experience - so what's the recommended time period to be allowed to get MFA question?
c. Is this due to development vs. production environment difference?
d. I can retrieve account and holdings details for account, however than the account results in NON_REFRESHABLE state.
After calling addSiteAccount1 API, you get siteAccountId for an account.
Pass the siteAccountId to getMFAResponseForSite API and keep polling until you get the MFA form. then pass the MFA form with valid values to putMFARequestForSite API.
Please refer to our API flow- https://developer.yodlee.com/Aggregation_API/Aggregation_Services_Guide/API_Flow/Add_Site_Account
Blockquote
Sample response-
{ "isMessageAvailable": true, "fieldInfo": {
"questionAndAnswerValues": [
{
"question": "What is the name of your state?",
"questionFieldType": "label",
"responseFieldType": "text",
"isRequired": "true",
"sequence": 1,
"metaData": "QUESTION_1"
},
{
"question": "What is the name of your first school",
"questionFieldType": "label",
"responseFieldType": "text",
"isRequired": "true",
"sequence": 2,
"metaData": "QUESTION_2"
}
],
"numOfMandatoryQuestions": 2,
"mfaFieldInfoType": "SECURITY_QUESTION" }, "timeOutTime": 97340, "itemId": 0, "memSiteAccId": 10003775, "retry": false }

Setting product published date via Shopify API doesn't work properly

When I set the published_at to a furture date by using the following JSON via Shopify product update API (https://ashop.myshopify.com/admin/products/product_id.json PUT).
{
"product": {
"id": 632910392,
"published": false,
"published_at": "2015-01-01T00:00:00+11:00"
}
}
It returned 200 and the following JSON
{
"product": {
"body_html": "something",
"created_at": "2014-01-07T14:49:00+11:00",
"handle": "test-product",
"id": 206281997,
"product_type": "MERCHANDISE",
"published_at": "2015-01-01T00:00:00+11:00",
"published_scope": "",
},
/* some other JavaScript properties*/
}
Shopify accepted the published date but the product was still visible. Below is the screenshot of the product Visibility
But if I removed "published_at": "2015-01-01T00:00:00+11:00" from the request JSON, the product changed to hidden.
How can I set the published date via Shopify API? Is it possible a Shopify API's bug?
Thanks for you help.
I have found a solution by using private API. And I tested it. Use publish_on instead of published_at. please refer to Shopify forums http://ecommerce.shopify.com/c/shopify-apis-and-technology/t/setting-product-published-date-via-shopify-api-doesn-t-work-properly-173469