Paypal API - checkout.js - parse response error - paypal

I've implemented this API on my Angular app. The issue is when I'm entering wrong shipping address the API is throwing the error:
Uncaught Error: An error was encountered while handling error
Error: Request to post www.sandbox.paypal.com/v1/payments/payment failed with 400 error. Correlation id: 3b331f9eaafa4, 3b331f9eaafa4
{
"name": "VALIDATION_ERROR",
"details": [
{
"field": "city",
"issue": "Value is invalid"
},
{
"field": "state",
"issue": "Value is invalid"
},
{
"field": "zip",
"issue": "Value is invalid"
}
],
"message": "Invalid request - see details",
"information_link": "developer.paypal.com/docs/api/payments/#errors",
"debug_id": "3b331f9eaafa4"
}
How do I parse the error in order to show a alert with the error's text? It's not JSON, so I don't know how to have it parsed.

This is the solution:
let res = error.message.match(/{([\s\S]*?)^}/gm);
console.log( JSON.parse( res[0] ) )
This will give a JSON to work with.

Use regex to match the JSON and then parse it to JSON using JSON.parse. Once done you can use the message and details fields which contain the information related to the error.
var jsonString = errmsg.match(/\{.*\}/gm);
var jsonObj = JSON.parse(jsonString);
Hope this helps.

Related

How to create a BigQuery View using REST request

I've tried building and sending the REST request using the Google Tables: insert page with the following (sanitised) values:
Request parameters
projectId:prj-name
datasetId:dataset_name
Request body
{
"view": {
"useLegacySql": false,
"query": "SELECT * FROM `prj-name.dataset_name.hello_world`"
},
"type": "VIEW",
"tableReference": {
"projectId": "prj-name",
"datasetId": "dataset_name",
"tableId": "v_hello_world"
}
}
This post suggests these parameters should work, but Google returns the following response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Output field used as input"
}
],
"code": 400,
"message": "Output field used as input"
}
}
I've experimented with the REST properties and I think the 400 issue is caused by the inclusion of the tableReference property. But if I exclude it I get the following alternative error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter is missing"
}
],
"code": 400,
"message": "Required parameter is missing"
}
}
It's a shame that the "Required parameter" is not named in this error message!
I can use this code method to create the view but that code method throws an exception when patching views.
Help is appreciated. I'd rather not have to maintain two different ways of managing views in my code.
Thanks.
Remove "type": "VIEW", from your request.
That's not an input parameter. It's an output field from the response.
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#resource

(#100) Tried accessing nonexisting field (consume) on node type (GamesIAPOrder)

I'm trying implement Payments Lite.
Purchase request works without any issues.
Same for purchases list. It returns:
[
{
"purchase_token": "###",
"product_id": "###",
"app_id": "###",
"purchase_time": ###,
"payment_id": "######",
"consumed": false,
"signed_request": "###",
"payment_action_type": "charge"
}
]
But if I try to consume this purchase using purchase_token the request returns:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (consume) on node type (GamesIAPOrder)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "CPjKLsTkf/G
"
}
}
I'm using this code:
FB.API("/" + purchaseToken + "/consume", HttpMethod.GET, OnConsume, new Dictionary<string, string> {
{"access_token", accessToken}
});
How can I solve it?
The call to consume a purchase_token should be using HttpMethod.POST instead of HttpMethod.GET
https://developers.facebook.com/docs/games_payments/payments_lite#consuming

firebase - Firestore REST API starting query

Hello I am new to firestore and I'm trying to use the rest API to query from a collection called Users, find all users who have a field called about with the value test2
This is my POST request :
https://firestore.googleapis.com/v1beta1/projects/{myprojectid}/databases/(default)/documents/Users:runQuery
Body:
{
"structuredQuery": {
"where" : {
"fieldFilter" : {
"field": {"fieldPath": "about"},
"op":"EQUAL",
"value": {"string": "test2"}
}
},
"from": [{"collectionId": "Users"}]
}
}
I get a response
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"structured_query\" at 'document': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid JSON payload received. Unknown name \"structured_query\" at 'document': Cannot find field."
}
]
}
]
}
}
Can someone tell me what I am doing wrong ? Thanks a lot. I'm stuck and unable to proceed.
In your URL get rid of the Users.
https://firestore.googleapis.com/v1beta1/projects/{myprojectid}/databases/(default)/documents:runQuery
Also, use stringValue instead of string value type. https://cloud.google.com/firestore/docs/reference/rest/v1beta1/Value
Just remember that you need to convert the url and take care with the version v1beta1 or v1, so in final form it will be like this:
https://firestore.googleapis.com/v1/projects/{myprojectid}/databases/%28default%29/documents:runQuery

VALIDATION_ERROR : "Field is invalid in a request"

I am trying to create agreement using paypal rest api.
POST https://api.sandbox.paypal.com/v1/payments/billing-agreements
In the request body i am passing "agreement_details" and other required fields such as name , description etc as per the documentation.
https://developer.paypal.com/docs/api/payments.billing-agreements#agreement_create
"agreement_details": {
"outstanding_balance": {
"value": "0.00"
},
"cycles_remaining": "4",
"cycles_completed": "0",
"final_payment_date": "2016-12-22T20:53:43Z",
"failed_payment_count": "0"
}
Status: 400 Bad Request
{
"name": "VALIDATION_ERROR",
"details": [
{
"field": "agreement_details",
"issue": "Field is invalid in a request."
}
],
"message": "Invalid request. See details.",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR",
"debug_id": "2fcb57fb9581f"
}

GoodData "Create Report Definition" API Call giving 500 Internal Server Error

I'm trying to create a report definition using the GoodData REST API. I use the following endpoint to invoke the rest call.
"/gdc/md/{project-id}/obj"
When i try to invoke the API call with the following dataset in which the projectId and the userId are valid, it gives me the error with the response code 500.
{
"reportDefinition": {
"content": {
"filters": [],
"format": "grid",
"grid": {
"rows": [],
"columns": [
"metricGroup"
],
"sort": {
"columns": [],
"rows": []
},
"columnWidths": [],
"metrics": [
{
"uri": "/gdc/md/qy48iv4flikdlcwpwioizuip74wt8nb5/obj/63f3cecd2a8d3ce2ec9378381c8f39e3",
"alias": ""
}
]
}
},
"meta": {
"title": "Sample report definition",
"summary": "This is a sample report",
"tags": "",
"deprecated": 0,
"category": "samplecategory"
}
}
}
{
"error": {
"message": "Internal server error. Please fill in bug report with request_id='lp78FL5S1IPMqB2n'"
}
}
I'm certain that the user project_id and the user_id are valid. Is this an error in the API?
Thank you in advance.
Apart from the metrics URI that looks weird (hash instead of numeric ID), I was able to dig in our logs an error that says: "Category is not equal to tag structure".
In your example you have its value set to "samplecategory". "category" property defines what type of object are you creating. If you are creating a report definition it should have value of "reportDefinition".
Last time I worked with GoodData API, metrics had numeric IDs. That seems most likely to be the culprit. Where did you get "/gdc/md/qy48iv4flikdlcwpwioizuip74wt8nb5/obj/63f3cecd2a8d3ce2ec9378381c8f39e3" from, especially the "63f3cecd2a8d3ce2ec9378381c8f39e3" part?