How JSON format for calling Checking out REST Api of Broadleaf commerce looks like - rest

I have followed setting up Broadleaf to make it running by following its documentation (http://docs.broadleafcommerce.org/current/REST-Tutorials.html). I wanted to do checking out the cart using REST Api; that's, /cart/checkout. Therefore, I looked inside the code in order to understand how the JSON format being sent will look alike. By looking through the code, I found that it is required to pass the JSON data as shown following:
{
"paymentInfo": {
"id": ,
"orderId": ,
"type": ,
"address": {
"id":
"firstname":
"lastname":
"addressLine1":
"addressLine2":
"city":
"state":
"country":
"postalCode":
},
"phone": "",
"additionalFields": "",
"amount": "",
"amountItems": "",
"customerIpAddress": "",
"referenceNumber": ""
},
"referenced": {
"id": "",
"referenceNumber": "",
"type": "",
"pan": "",
"cvvCode:" "",
"expirationMonth": "",
"expirationYear": "",
"accountNumber": "",
"routingNumber": "",
"pin": ""
}
}
However, I have no idea such the JSON data looks like. Therefore, if anyone who has ever used the api, please help me by showing an example of data in order to make the request. Looking forward to the answers.
Thanks in advance.

All of our REST APIs are exposed through a 'wrapper' concept. For instance, there is a CustomerWrapper, OrderWrapper, etc. These wrappers define which properties are serialized back and forth with the REST APIs.
For your specific case, you should look at PaymentReferenceMapWrapper.

{
"id": 1751,
"status": "IN_PROCESS",
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"totalShipping": {
"amount": "0.00",
"currency": "INR"
},
"subTotal": {
"amount": "860.00",
"currency": "INR"
},
"total": {
"amount": "860.00",
"currency": "INR"
},
"customer": {
"id": 2600
},
"orderItems": [
{
"id": 1752,
"name": "abc",
"quantity": 2,
"retailPrice": {
"amount": "430.00",
"currency": "INR"
},
"salePrice": {
"amount": "430.00",
"currency": "INR"
},
"orderId": 1751,
"categoryId": 10300,
"skuId": 10212,
"productId": 10212,
"isBundle": false,
"orderItemPriceDetails": [
{
"id": 1752,
"totalAdjustmentValue": {
"amount": "0.00",
"currency": "INR"
},
"totalAdjustedPrice": {
"amount": "860.00",
"currency": "INR"
},
"quantity": 2,
"adjustments": []
}
],
"isDiscountingAllowed": true
}
],
"fulfillmentGroups": [
{
"id": 1502,
"orderId": 1751,
"total": {
"amount": "860.00",
"currency": "INR"
},
"fulfillmentGroupItems": [
{
"id": 1752,
"fulfillmentGroupId": 1502,
"orderItemId": 1752,
"totalTax": {
"amount": "0.00",
"currency": "INR"
},
"quantity": 2,
"totalItemAmount": {
"amount": "860.00",
"currency": "INR"
}
}
]
}
],
"payments": [
{
"id": 601,
"orderId": 1751,
"type": "COD",
"amount": "860.00",
"currency": "INR",
"gatewayType": "Passthrough",
"transactions": [
{
"id": 601,
"orderPaymentId": 601,
"type": "AUTHORIZE_AND_CAPTURE",
"success": true,
"amount": "860.00",
"currency": "INR"
}
]
}
]
}
This is the same json you will get from /cart?customerId="" with method GET after successfully executing /cart/checkout/payment

Related

PayPal API returns SUBSCRIPTION_CANNOT_HAVE_QUANTITY even though Plan has quantity_supported set

Using PayPal's current API I've created a simple Product:
{
"id" : "A-001",
"name": "A Service",
"description": "Video streaming service",
"type": "SERVICE",
"category": "SOFTWARE"
}
Also created a Plan, which is tiered based on Quantity
{
"product_id" : "A-001",
"name": "Default Plan",
"description": "Plan with regular and trial payment definitions.",
"quantity_supported" : true,
"billing_cycles": [
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "TRIAL",
"sequence": 1,
"total_cycles": 1
},
{
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 2,
"total_cycles": 12,
"pricing_scheme": {
"pricing_model" : "TIERED",
"version" : 1,
"tiers": [{
"starting_quantity": 1,
"ending_quantity": 499,
"amount": { "currency_code":"USD", "value":0.55}
},
{
"starting_quantity": 500,
"ending_quantity": 999,
"amount": { "currency_code":"USD", "value":0.5}
},
{
"starting_quantity": 1000,
"ending_quantity": 2499,
"amount": { "currency_code":"USD", "value":0.46}
},
{
"starting_quantity": 2500,
"amount": { "currency_code":"USD", "value":0.37}
}
]
}
}
],
"payment_preferences": {
"auto_bill_outstanding": true,
"setup_fee": {
"value": "10",
"currency_code": "USD"
},
"setup_fee_failure_action": "CONTINUE",
"payment_failure_threshold": 3
},
"taxes": {
"percentage": "10",
"inclusive": false
}
}
Now, I try to create a Subscription to the Plan:
{
"plan_id": "P-16786052YT8021220MAMUCDY",
"start_time": "2021-03-01T00:00:00Z",
"quantity": "20",
"shipping_amount": {
"currency_code": "USD",
"value": "0.00"
},
"subscriber": {
"name": {
"given_name": "John",
"surname": "Doe"
},
"email_address": "customer#example.com",
"shipping_address": {
"name": {
"full_name": "John Doe"
},
"address": {
"address_line_1": "2211 N First Street",
"address_line_2": "Building 17",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
},
"application_context": {
"brand_name": "walmart",
"locale": "en-US",
"shipping_preference": "SET_PROVIDED_ADDRESS",
"user_action": "SUBSCRIBE_NOW",
"payment_method": {
"payer_selected": "PAYPAL",
"payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url": "https://example.com/returnUrl",
"cancel_url": "https://example.com/cancelUrl"
}
}
But I get an Error response:
{
"name": "UNPROCESSABLE_ENTITY",
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "658174d246c0b",
"details": [
{
"issue": "SUBSCRIPTION_CANNOT_HAVE_QUANTITY",
"description": "Subscription can't have quantity as the plan does not support quantity."
}
],
"links": [
{
"href": "https://developer.paypal.com/docs/api/v1/billing/subscriptions#UNPROCESSABLE_ENTITY",
"rel": "information_link",
"method": "GET"
}
]
}
Why do I get this error when my Plan clearly states "quantity_supported" : true, ?
In my case I had forgotten to modify the PayPal-Request-Id from a previous Plan creation (which didn't allow Quantity), so the Plan with details above wasn't being created

How to properly insert documents into a collection using the MongoDB Web Shell

I am having some trouble inserting a collection of documents into a MongoDB Web Shell from the mongodb site.
The link provided: https://docs.mongodb.com/manual/tutorial/insert-documents/
Here is what I have for a simple example:
db.FirstExample.insertMany ([
{ "Date": "2001-01-01", "Description": "Airfare", "Amount": "500.34" },
{ "Date": "2001-01-01", "Description": "Hotel", "Amount": "200" },
{ "Date": "2001-01-01", "Description": "Taxi Fare", "Amount": "100.00" },
{ "Date": "2001-01-01", "Description": "Long Distance Phone Charges", "Amount": "57.89" },
{ "Date": "2001-01-01", "Description": "Food", "Amount": "82.19" },
{ "Date": "2001-01-02", "Description": "Food", "Amount": "17.89" },
{ "Date": "2001-01-02", "Description": "Personal Items", "Amount": "32.54" },
{ "Date": "2001-01-03", "Description": "Taxi Fare", "Amount": "75.00" },
{ "Date": "2001-01-03", "Description": "Food", "Amount": "36.45" },
{ "Date": "2001-01-03", "Description": "New Suit", "Amount": "750.00" }
]);
When I run this collection into the MongoDB Web Shell, it works perfectly. Now here's the trouble, I want to include one more element called "ExpenseItem". When I enter the new code snippet, I get an error.
db.FirstExample.insertMany ([
{ "ExpenseItem:"
{ "Date": "2001-01-01", "Description": "Airfare", "Amount": "500.34" },
{ "Date": "2001-01-01", "Description": "Hotel", "Amount": "200" },
{ "Date": "2001-01-01", "Description": "Taxi Fare", "Amount": "100.00" },
{ "Date": "2001-01-01", "Description": "Long Distance Phone Charges", "Amount": "57.89" },
{ "Date": "2001-01-01", "Description": "Food", "Amount": "82.19" },
{ "Date": "2001-01-02", "Description": "Food", "Amount": "17.89" },
{ "Date": "2001-01-02", "Description": "Personal Items", "Amount": "32.54" },
{ "Date": "2001-01-03", "Description": "Taxi Fare", "Amount": "75.00" },
{ "Date": "2001-01-03", "Description": "Food", "Amount": "36.45" },
{ "Date": "2001-01-03", "Description": "New Suit", "Amount": "750.00" }
}
]);
The error is this:
E QUERY [js] uncaught exception: SyntaxError: missing : after property id :
Why am I getting the error? Isn't the ":" already next to the "ExpsenseItem"? What key detail am I missing for this code snippet not running in the MongoDb Web Shell?
The colon separating they key ExpenseItem from the rest of the document is inside the quotes so is considered part of the key. To nest the documents as they are you would need to put them inside an array. As so:
{ "ExpenseItem" : [
{ "Date": "2001-01-01", "Description": "Airfare", "Amount": "500.34" },
{ "Date": "2001-01-01", "Description": "Hotel", "Amount": "200" },
{ "Date": "2001-01-01", "Description": "Taxi Fare", "Amount": "100.00" },
{ "Date": "2001-01-01", "Description": "Long Distance Phone Charges", "Amount": "57.89" },
{ "Date": "2001-01-01", "Description": "Food", "Amount": "82.19" },
{ "Date": "2001-01-02", "Description": "Food", "Amount": "17.89" },
{ "Date": "2001-01-02", "Description": "Personal Items", "Amount": "32.54" },
{ "Date": "2001-01-03", "Description": "Taxi Fare", "Amount": "75.00" },
{ "Date": "2001-01-03", "Description": "Food", "Amount": "36.45" },
{ "Date": "2001-01-03", "Description": "New Suit", "Amount": "750.00" }
]
}
This document will insert but it is now a single document.

How to check $exists in one to many relationship mongodb sails js?

Is there any way to find records that collection is empty?
For example please find below array. I want only that records with index "companydata" is empty. and also how can i get data that does not have empty "companydata" data.
Thanks in advance.
[
{
"company_id": {
"company_name": "C2",
"slug": "c2",
"is_organized": 1,
"status": "1",
"id": "5adf158f547f7f0314ca8b56",
"companydata": []
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ae014e7432e85298081be0b"
},
{
"company_id": {
"company_name": "My Compnay",
"slug": "my-compnay",
"is_organized": 1,
"status": "1",
"id": "5ad442d98a0e0c1358ca93df",
"companydata": [
{
"name": "Bhavesh Amin",
"company_id": "5ad442d98a0e0c1358ca93df",
"status": "0",
"id": "5ad442da8a0e0c1358ca93e0"
}
]
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ae01388432e85298081bdf8"
},
{
"company_id": {
"company_name": "Organization Name",
"slug": "organization-name",
"is_organized": 1,
"status": "1",
"id": "5ad08f9b938d1131eceea624",
"companydata": [
{
"name": "Helen H. Langley",
"company_id": "5ad08f9b938d1131eceea624",
"status": "1",
"id": "5ad08f9b938d1131eceea625"
}
]
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ad42a5f52851a2b1449db2d"
},
]

Update single sub document in multiple array in mgo

I have following mongodb (3.4.x) document, i code in golang with mgo driver
{
"id": "5981d4c2795a1b4a801ee027",
"scenarioId": "59804b10d8ee910085e33865",
"messages": [
{
"id": "5981d4c2795a1b4a801ee028",
"toQueue": [
{
"id": "5981d4c2795a1b4a801ee029",
"to": {
"email": "some#email.com"
},
"channel": "EMAIL",
"toType": "EMAIL",
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
},
{
"id": "5981d4c2795a1b4a801ee02a",
"to": {
"phone": "+381631891245"
},
"channel": "SMS",
"toType": "PHONE",
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
],
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
},
{
"id": "5981d4c2795a1b4a801ee02b",
"toQueue": [
{
"id": "5981d4c2795a1b4a801ee02c",
"to": {
"phone": "+123456789"
},
"channel": "SMS",
"toType": "PHONE",
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
],
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
],
"messageStages": [
{
"id": "5981d4c2795a1b4a801ee033",
"validityPeriod": 5,
"validityPeriodTimeUnit": "MINUTES",
"providerId": 5,
"email": {
"text": "this is the email text",
"subject": "and here the email subject"
},
"status": {
"id": 1,
"groupId": 1,
"groupName": "PROCESSING",
"name": "APPROVED",
"description": "MessageChain approved for processing"
}
}
]
}
and I know the value of messages.$.toQueue.id, where i want to update status.id in the related toQueue Array Item.
I tried to do it that way:
query = bson.M{
"messages.toQueue._id": toQueueId,
}
update = bson.M{
"$set": bson.M{
"messages.$.toQueue.$.status.id": status.Id,
"messages.$.toQueue.$.status.name": status.Name,
"messages.$.toQueue.$.status.groupId": status.GroupId,
"messages.$.toQueue.$.status.groupName": status.GroupName,
"messages.$.toQueue.$.status.description": status.Description,
},
}
err = cr.Update(query,update)
but multiple $ are not allowed. Without it's also not updateable.
Is there any way to update only the subdocument, which i found in query ?
Neil Lunn gave the right answer.
It's not possible to work with nested arrays the way I tried to do. And he is also right, that problem is coming from design mistake.
So I changed it as him and Markus W Mahlberg suggested to move the toQueue part in a separate collection, with messageId as a reference.

what is the date format from stash api?

In the below json response, what is the date format for createdDate and updatedDate? I am not sure how to work in reverse to find what format the api is using for date. I couldn't find this any where in the documentation.
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"id": 101,
"version": 1,
"title": "Talking Nerdy",
"description": "It’s a kludge, but put the tuple from the database in the cache.",
"state": "OPEN",
"open": true,
"closed": false,
"createdDate": 1359075920,
"updatedDate": 1359085920,
"fromRef": {
"id": "refs/heads/feature-ABC-123",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"toRef": {
"id": "refs/heads/master",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"locked": false,
"author": {
"user": {
"name": "tom",
"emailAddress": "tom#example.com",
"id": 115026,
"displayName": "Tom",
"active": true,
"slug": "tom",
"type": "NORMAL"
},
"role": "AUTHOR",
"approved": true
},
"reviewers": [
{
"user": {
"name": "jcitizen",
"emailAddress": "jane#example.com",
"id": 101,
"displayName": "Jane Citizen",
"active": true,
"slug": "jcitizen",
"type": "NORMAL"
},
"role": "REVIEWER",
"approved": true
}
],
"participants": [
{
"user": {
"name": "dick",
"emailAddress": "dick#example.com",
"id": 3083181,
"displayName": "Dick",
"active": true,
"slug": "dick",
"type": "NORMAL"
},
"role": "PARTICIPANT",
"approved": false
},
{
"user": {
"name": "harry",
"emailAddress": "harry#example.com",
"id": 99049120,
"displayName": "Harry",
"active": true,
"slug": "harry",
"type": "NORMAL"
},
"role": "PARTICIPANT",
"approved": true
}
],
"link": {
"url": "http://link/to/pullrequest",
"rel": "self"
},
"links": {
"self": [
{
"href": "http://link/to/pullrequest"
}
]
}
}
],
"start": 0
}
Just making a note that in my case, it is a UNIX timestamp, but I have to remove three trailing zeroes. E.g. the data looks like this:
"createdDate":1555621993000
If interpreted as a UNIX timestamp, that would be 09/12/51265 # 4:16am (UTC).
By removing the three trailing zeroes I get 1555621993, which is the correct time 04/18/2019 # 9:13pm (UTC)
Your mileage may vary but that was a key discovery for me :)
It looks like a UNIX timestamp.
https://en.wikipedia.org/wiki/Unix_time