PayPal Orders Create: Status 422, amount mismatch error despite matching values - paypal

I am receiving a 422 UNPROCESSABLE_ENTITY error from paypal, indicating that my amount->value and breakdown values don't match up, but as far as I can tell they aren't. The request body is as follows:
"amount": {
"currency_code": "USD",
"value": 5,
"breakdown": {
"item_total": {
"value": 10,
"currency_code": "USD",
"discount": {
"value": 5,
"currency_code": "USD"
}
}
}
}
The error message says about amount->value: Should equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount.
Since I don't have shipping/handling/insurance/etc, shouldn't it just be 5(amount) = 10(item_total) - 5(discount)? What am I missing here?
Also, just in case it matters, I have just a single item in the purchase unit:
"items": [
{
"name": "...",
"unit_amount": {
"value": 10,
"currency_code": "USD"
},
"quantity": 1,
"category": "DIGITAL_GOODS"
}
]

discount is in the wrong place here:
"breakdown": {
"item_total": {
"value": 10,
"currency_code": "USD",
"discount": {
"value": 5,
"currency_code": "USD"
}
}
}
Move it out of item_total (where it's being ignored as an unknown field), and into the parent breakdown object where it belongs.

For PHP that would be :
$request->body = [
'intent' => 'CAPTURE',
'purchase_units' => [
[
'invoice_id' => 'some-id',
'amount' => [
'value' => 15,
'currency_code' => 'EUR',
'breakdown' => [
'shipping' => [
'value' => 5,
'currency_code' => 'EUR',
],
'item_total' => [
'value' => 10,
'currency_code' => 'EUR',
]
],
],
],
],
'application_context' => [
'cancel_url' => $cancelUrl,
'return_url' => $returnUrl,
],
];

Related

How to handle tags and hierarchies in ag-grid table data structure?

I would like to use the pivot feature, but since my data has a lot of tags (1-level nested), I'm not sure how to make ag-grid parse this data and recognize it.
Here's the data for example:
[
{
"_id": "1",
"symbol": "sym1",
"open_date": "2019-04-23",
"_type": "t1",
"currency": "USD",
"quantity": 456,
"tags": [
{
"tag": "G_TAG1",
"group_name": "Group_1",
},
{
"tag": "G_TAG2",
"group_name": "Group_1",
}
],
},
{
"_id": "2",
"symbol": "sym2",
"open_date": "2029-01-11",
"_type": "t2",
"currency": "EUR",
"quantity": 312,
"tags": [
{
"tag": "G3_TAG-ABC",
"group_name": "Group_3",
},
{
"tag": "G2_TAG-DEF",
"group_name": "Group_2",
},
{
"tag": "G_TAG3",
"group_name": "Group_1",
}
],
},
{
"_id": "3",
"symbol": "sym3",
"open_date": "2010-12-01",
"_type": "t3",
"currency": "AUD",
"quantity": 123,
"tags": [
{
"tag": "G_TAG3",
"group_name": "Group_1",
}
],
}
]
In columnDefs, I defined tags column like this:
{field:'tags',
enablePivot: true,
children: [
{
headerName: "Tag", valueGetter: params => params.data.tags.map(x => x.tag),
enablePivot: true,
},
{
headerName: "Tag Group", valueGetter: params => params.data.tags.map(x => x.group_name),
enablePivot: true,
},
]
},
Each data point has a list of tags and each tag can belong to a group or not. So the top-most hierarchy is the tag group and below that are the individual tags.
Is there a way aggrid can recognize this or a way I can transform the data so visualize per-tag or per-group statistics? For example, can I view stats grouped by tag group > tag > symbol?

REST API response of Array Data Provider

I am developing api to get all users
URL is
v1/users?fields=id,full_name
Here is the code
public function actionIndex() {
$provider = new ArrayDataProvider([
'allModels' => User::find()->all(),
'sort' => [
'attributes' => ['id'],
],
'pagination' => [
'pageSize' => 10,
],
]);
return $provider;
}
OUT put is
[
{
"id": 4,
"full_name": "Shahid admin"
},
{
"id": 6,
"full_name": "First client"
}
]
But when i change the out put in another format:
return (new ApiResponse)->success(['user' => $provider], ApiResponse::success);
then output is changed ie give me whole object of user model and pagination not working
{
"name": "Success",
"message": "Success",
"code": 200,
"status": "",
"type": "Response",
"models": {
"user": {
"key": null,
"allModels": [
{
"id": 6,
"full_name": "First client",
"profile_image_id": null,
"profile_image": null,
"isverify": 1
},
{
"id": 7,
"full_name": "Eng instrcutor",
"profile_image_id": null,
"profile_image": null,
"isverify": 1
},

Data retrieve using entity framework issue in dotnet core

I have a table with user answers.Assume survey contains 5 questions.Then this row contains 5 rows per user.I want to retrive it like
userEmail: 'amara#gmail.com',
qustns: []
Here is the json data what I want.
uersSurveyAnswers: any = [
{
userEmail: 'amara#gmail.com',
qustns: [
{
qNo: 1,
ansrs: ['1']
},
{
qNo: 2,
ansrs: ['1', '0', '1', '1']
},
{
qNo: 5,
ansrs: ['2']
},
{
qNo: 6,
ansrs: ['0', '1', '1', '0']
}
]
},
{
userEmail: 'saman#gmail.com',
qustns: [
{
qNo: 1,
ansrs: ['3']
},
{
qNo: 2,
ansrs: ['0', '0', '1', '1']
},
{
qNo: 5,
ansrs: ['1']
},
{
qNo: 6,
ansrs: ['1', '1', '0', '0']
}
]
}]
But it returns like this
[
{
"userEmail": "amara#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"2"
]
},
{
"qNo": 2,
"ansrs": [
"1",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"1",
"2",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Blue"
]
}
]
},
{
"userEmail": "amara#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"2"
]
},
{
"qNo": 2,
"ansrs": [
"1",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"1",
"2",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Blue"
]
}
]
},
{
"userEmail": "amara#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"2"
]
},
{
"qNo": 2,
"ansrs": [
"1",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"1",
"2",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Blue"
]
}
]
},
{
"userEmail": "amara#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"2"
]
},
{
"qNo": 2,
"ansrs": [
"1",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"1",
"2",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Blue"
]
}
]
},
{
"userEmail": "saman#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"1"
]
},
{
"qNo": 2,
"ansrs": [
"0",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"2",
"1",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Green"
]
}
]
},
{
"userEmail": "saman#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"1"
]
},
{
"qNo": 2,
"ansrs": [
"0",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"2",
"1",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Green"
]
}
]
},
{
"userEmail": "saman#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"1"
]
},
{
"qNo": 2,
"ansrs": [
"0",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"2",
"1",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Green"
]
}
]
},
{
"userEmail": "saman#gmail.com",
"qustns": [
{
"qNo": 1,
"ansrs": [
"1"
]
},
{
"qNo": 2,
"ansrs": [
"0",
"0",
"1",
"1"
]
},
{
"qNo": 3,
"ansrs": [
"2",
"1",
"4",
"3"
]
},
{
"qNo": 4,
"ansrs": [
"Green"
]
}
]
}]
Here is my code
var qstns = await (from uans in _context.UserAnswers
where uans.SurveyId == id
select new UserAnswersReturnDto
{
UserEmail = uans.CreatedBy,
Qustns = (from ans in _context.UserAnswers
where ans.CreatedBy == uans.CreatedBy
select new UserAnswersSet
{
QNo = ans.QNo,
Ansrs = JsonConvert.DeserializeObject<JArray>(string.IsNullOrEmpty(ans.Answers) ? "[]" : ans.Answers)
}).ToArray()
}).ToListAsync();
How to resolve this issue.
here is my table view screen.
I think this issue will resolve if I add group by.But I tried it.I can't understand how to use it.please help me
Your json sample with uersSurveyAnswers: any = [...] isn't valid. I guess you meant uersSurveyAnswers: [...].
What you are looking for in this case is making an object that contains your collection of UserAnswersReturnDto. You can simply return the following to do this:
return new { uersSurveyAnswers = qstns };

Handling 'or' and 'and' condition for fetching data in project

I have a collection with data like
"Name": "....",
...
"RoomStatusDetails": [
{
"StatusEntryId": ObjectId("5be1895dbb2c5620c4003ae0"),
"RoomId": "41964158-0131-7b55-7781-a29084879e1a",
"CurrentStatus": ObjectId("5bd17295d2ccda11f0007765"),
"StartDate": ISODate("2018-11-06T05:00:00.0Z"),
"Notes": "",
"Discrepancy": "",
"Waiver": "",
"TFlight": "",
"IsActive": "Inactive"
},
{
"StatusEntryId": ObjectId("5be1896cbb2c5620c4003ae1"),
"RoomId": "41964158-0131-7b55-7781-a29084879e1a",
"CurrentStatus": ObjectId("5bd17295d2ccda11f0007766"),
"StartDate": ISODate("2018-11-06T05:00:00.0Z"),
"Notes": "",
"Discrepancy": "",
"Waiver": "",
"TFlight": "",
"IsActive": "Active"
},
{
"StatusEntryId": ObjectId("5bf4e8a83250041388000edf"),
"RoomId": "d72136ac-b295-d4ea-2d32-0f9ef26b7df1",
"CurrentStatus": ObjectId("5bd17295d2ccda11f0007766"),
"StartDate": ISODate("2018-11-26T23:00:00.0Z"),
"Notes": "",
"Discrepancy": "",
"Waiver": "",
"TFlight": "",
"IsActive": "Active"
},
{
"StatusEntryId": ObjectId("5bf4e8db3250041388000ee0"),
"RoomId": "4c980185-65eb-eece-8176-7f187eed3132",
"CurrentStatus": ObjectId("5bd17295d2ccda11f0007765"),
"StartDate": ISODate("2018-11-18T23:00:00.0Z"),
"Notes": "",
"Discrepancy": "",
"Waiver": "",
"TFlight": "",
"IsActive": "Active"
},
{
"StatusEntryId": ObjectId("5bf4e97f3250041388000ee1"),
"RoomId": "407225eb-2990-263b-4112-068d3ef0e1b2",
"CurrentStatus": ObjectId("5bd17295d2ccda11f0007768"),
"StartDate": ISODate("2018-12-05T23:00:00.0Z"),
"Notes": "",
"Discrepancy": "",
"Waiver": "",
"TFlight": "",
"IsActive": "Active"
}
],
I am trying below lines of code
$this->collection->aggregate(array(
array(
'$project' => array(
'RoomStatusDetails' => array(
'$filter' => array(
'input' => '$RoomStatusDetails',
'as' => 'item',
'cond' => array(
'$or' => [
['$eq' => ['$$item.CurrentStatus', new MongoDB\BSON\ObjectID($this->CAOutOfService)]],
['$eq' => ['$$item.CurrentStatus', new MongoDB\BSON\ObjectID($this->OutOfService)]]
],
['$eq' => ['$$item.IsActive', 'Active']]
)
)
),
'Name' => 1,
'Address' => 1,
'NoOfFloors' => 1,
'Image' => 1,
'Bay' => 1,
'Approved' => 1,
'RoomsDetails' => 1,
'AllotmentsDetails' => 1,
//'TotalNumberOfCapacitiesArray' => 1
)
),
))->toArray();
I am trying to project embedded document RoomStatusDetails and I am trying to fetch only those RoomStatusDetails data where Current Status can be "5bd17295d2ccda11f0007765" or "5bd17295d2ccda11f0007766" which are present in $this->CAOutOfService or $this->OutOfService variables respectively and their IsActive is "Active".
The above code is throwing error "An object representing an expression must have exactly one field: { $or: [ { $eq: [ \"$$item.CurrentStatus\", ObjectId('5bd17295d2ccda11f0007769') ] }, { $eq: [ \"$$item.CurrentStatus\", ObjectId('5bd17295d2ccda11f0007766') ] } ], 0: { $eq: [ \"$$item.IsActive\", \"Active\" ] } }"
Please help!!!
You can build your query like this
db.col.aggregate([{
"$project": {
"RoomStatusDetails": {
"$filter": {
"input": "$RoomStatusDetails",
"as": "stat",
cond: {
"$and": [{
$or: [{
$eq: ["$$stat.CurrentStatus", ObjectId("5bd17295d2ccda11f0007766")]
},
{
$eq: ["$$stat.CurrentStatus", ObjectId("5bd17295d2ccda11f0007765")]
}
]
},
{
$eq: ["$$stat.IsActive", "Active"]
}
]
}
}
}
}
}
])

Postgresql json query

I have one table with one column jsonb with the text:
[
{
"id": 1,
"nome": "AUTOMÓVEL",
"partes": [
{
"fracao": 100,
"documento": "111.111.111-11"
}
],
"atributos": [
{
"id": 3,
"nome": "MARCA",
"valor": "FORD"
},
{
"id": 2,
"nome": "MODELO",
"valor": "FIESTA"
},
{
"id": 1,
"nome": "RENAVAM",
"valor": "RENAVAM"
}
]
},
{
"id": 1,
"nome": "AUTOMÓVEL",
"partes": [
{
"fracao": 100,
"documento": "111.111.111-11"
}
],
"atributos": [
{
"id": 3,
"nome": "MARCA",
"valor": "FIAT"
},
{
"id": 2,
"nome": "MODELO",
"valor": "PALIO"
},
{
"id": 1,
"nome": "RENAVAM",
"valor": "RENAVAM"
}
]
},
{
"id": 1,
"nome": "AUTOMÓVEL",
"partes": [
{
"fracao": 100,
"documento": "111.111.111-11"
}
],
"atributos": [
{
"id": 3,
"nome": "MARCA",
"valor": "HONDA"
},
{
"id": 2,
"nome": "MODELO",
"valor": "FIT"
},
{
"id": 1,
"nome": "RENAVAM",
"valor": "RENAVAM"
}
]
}
]
so i create a select:
select objetos
from protocolo
where objetos #> '[{"id": 1 , "atributos": [{"nome": "MARCA", "valor" : "FIAT"}]}]'
but this select will return the column with all text, but I need to return only the element that match in my where clause
so I need to return only this:
{
"id": 1,
"nome": "AUTOMÓVEL",
"partes": [
{
"fracao": 100,
"documento": "111.111.111-11"
}
],
"atributos": [
{
"id": 3,
"nome": "MARCA",
"valor": "FIAT"
},
{
"id": 2,
"nome": "MODELO",
"valor": "PALIO"
},
{
"id": 1,
"nome": "RENAVAM",
"valor": "RENAVAM"
}
]
}
Use the function jsonb_array_elements():
select value
from protocolo
cross join lateral jsonb_array_elements(objetos)
where value #> '{"id": 1 , "atributos": [{"nome": "MARCA", "valor" : "FIAT"}]}';
Note that the json expression in the where clause has changed.