Hi i have the below response for Stripe in my Grails 2.5.1 application , how i can read and manipulate it using Grails .
Response :
<com.stripe.model.Charge#1467160391 id=ch_17bcduFKvYH0sAt4OMSKjOzA> JSON: { "amount": 7200, "created": 1454790414, "currency": "egp", "id": "ch_17bcduFKvYH0sAt4OMSKjOzA", "livemode": false, "paid": true, "refunded": false, "disputed": null, "captured": true, "description": "customer#sample.org", "statement_description": null, "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": null, "invoice": null, "refunds": { "data": [], "total_count": 0, "has_more": false, "url": "/v1/charges/ch_17bcduFKvYH0sAt4OMSKjOzA/refunds", "count": null }, "card": null, "dispute": null, "balance_transaction": "txn_17bcduFKvYH0sAt4qSSDZ7Bj", "metadata": {} }
Related
I have this example here and i'm trying to only query the empty mongodb array
var data = [{
"dynamic_env": null,
"mission_critical": null,
"chart-version": null,
"app-url": null,
"mongodb": {},
"nightly_shutdown": false,
"external_values": null,
"external_values_source": null,
"external_values_path": null,
"atlas_database": null,
"allow_db_restore": null,
"on-demand": false,
"helm_timeout": null,
"aws-account": null,
"post": [],
"pre": [],
"atlas_project": null,
"istio-enabled": false,
"env_subscription": null,
"istio-auth-policy": null,
"version": null,
"e2e-tests-script": [],
"morning_startup": true,
"project_dst": null,
"cred": null,
"dataset": null,
"project_src": null,
"Env": {
"identifier": "cm-infra-ci-core1#admin365-infra-stg-eks#admin365-cm-infra-ci-core1",
"title": "cm-infra-ci-core1"
},
"namespace": "admin365-cm-infra-ci-core1",
"cluster": {
"identifier": "admin365-infra-stg-eks#infra-stg",
"title": "admin365-infra-stg-eks"
},
"Service": {
"identifier": "user-data-management-gdpr-fetch",
"title": "user-data-management-gdpr-fetch"
},
"team": null,
"$identifier": "user-data-management-gdpr-fetch#cm-infra-ci-core1#admin365-cm-infra-ci-core1",
"$title": "user-data-management-gdpr-fetch#cm-infra-ci-core1"
},
{
"dynamic_env": null,
"mission_critical": null,
"chart-version": null,
"app-url": null,
"mongodb": {a: 123},
"nightly_shutdown": false,
"external_values": null,
"external_values_source": null,
"external_values_path": null,
"atlas_database": null,
"allow_db_restore": null,
"on-demand": false,
"helm_timeout": null,
"aws-account": null,
"post": [],
"pre": [],
"atlas_project": null,
"istio-enabled": false,
"env_subscription": null,
"istio-auth-policy": null,
"version": null,
"e2e-tests-script": [],
"morning_startup": true,
"project_dst": null,
"cred": null,
"dataset": null,
"project_src": null,
"Env": {
"identifier": "cm-infra-ci-core1#admin365-infra-stg-eks#admin365-cm-infra-ci-core1",
"title": "cm-infra-ci-core1"
},
"namespace": "admin365-cm-infra-ci-core1",
"cluster": {
"identifier": "admin365-infra-stg-eks#infra-stg",
"title": "admin365-infra-stg-eks"
},
"Service": {
"identifier": "user-data-management-gdpr-fetch",
"title": "user-data-management-gdpr-fetch"
},
"team": null,
"$identifier": "user-data-management-gdpr-fetch#cm-infra-ci-core1#admin365-cm-infra-ci-core1",
"$title": "user-data-management-gdpr-fetch#cm-infra-ci-core1"
}];
var res = alasql(`SELECT * FROM ? WHERE ('mongodb'->() = {})`,[data]);
console.log(res.length); // [{"a":1,"b":40},{"a":2,"b":20}]
Add a user-defined function that returns the number of keys in the object, then query it:
alasql.fn.keylen = function(x) { return Object.keys(x).length; }
var res = alasql(`SELECT * FROM ? WHERE keylen(mongodb) = 0`,[data]);
I used Create Call of Microsoft Graph API to create a group call(audio). The connection has created successfully, but every member cannot receive any chat message posted by other members.
(picture)The phenomenon that everyone cannot receive other's message
Request as below:
POST https://graph.microsoft.com/beta/app/calls
Content-Type: application/json
Authorization: Bearer <Token>
{
"#odata.type": "#microsoft.graph.call",
"callbackUri": "https://myhostname.ngrok.io/callback/calling",
"mediaConfig": {
"#odata.type": "#microsoft.graph.serviceHostedMediaConfig"
},
"source": {
"identity": {
"application": {
"id": "myCallingAppId"
}
}
},
"subject": "Test Call",
"targets": [
{
"identity": {
"user": {
"id": "User_1-Id",
"displayName": "User_1-DisplayName"
}
},
"identity": {
"user": {
"id": "User_2-Id",
"displayName": "User_2-Name"
}
}
}
],
"tenantId": "myCallingAppTenant"
}
Response:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#communications/calls/$entity",
"id": "481f0c00-ffff-41cd-bbc8-7e21fb5e8b1b",
"state": "establishing",
"transferState": null,
"terminationReason": null,
"direction": "outgoing",
"ringingTimeoutInSeconds": null,
"subject": "Test Call",
"callbackUri": "https://myhostname.ngrok.io/callback/calling",
"requestedModalities": [],
"activeModalities": [],
"routingPolicies": [],
"tenantId": "myCallingAppTenant",
"myParticipantId": "59e11e38-87d0-4ae5-b3ce-051ea26aa34d",
"mediaState": null,
"resultInfo": null,
"answeredBy": null,
"chatInfo": null,
"meetingInfo": null,
"meetingCapability": null,
"toneInfo": null,
"incomingContext": null,
"callRoutes": [],
"source": {
"region": null,
"languageId": null,
"identity": {
"user": null,
"device": null,
"phone": null,
"application": {
"id": "myCallingAppId",
"displayName": null
}
}
},
"targets": [
{
"region": null,
"languageId": null,
"identity": {
"application": null,
"device": null,
"phone": null,
"user": {
"id": "User_1-Id",
"displayName": "User_1-DisplayName"
}
}
},
{
"region": null,
"languageId": null,
"identity": {
"application": null,
"device": null,
"phone": null,
"user": {
"id": "User_2-Id",
"displayName": "User_2-DisplayName"
}
}
}
],
"mediaConfig": {
"#odata.type": "#microsoft.graph.serviceHostedMediaConfig",
"removeFromDefaultAudioGroup": null,
"preFetchMedia": []
}
}
Is any configuration missed. How to create a calling with normal message communication. Could anyone help me, thanks!
Im trying to implement stripe webhooks in my rails app. The webhook send this json data.
{ "created": 1326853478, "livemode": false, "id": "evt_00000000000000", "type": "invoice.payment_succeeded", "object": "event", "request": null, "pending_webhooks": 1, "api_version": "2017-06-05", "data": {
"object": {
"id": "in_00000000000000",
"object": "invoice",
"amount_due": 500,
"application_fee": null,
"attempt_count": 1,
"attempted": true,
"charge": "_00000000000000",
"closed": true,
"currency": "usd",
"customer": "cus_00000000000000",
"date": 1501950408,
"description": null,
"discount": null,
"ending_balance": 0,
"forgiven": false,
"lines": {
"data": [
{
"id": "sub_BLXcTSekdHflq5",
"object": "line_item",
"amount": 500,
"currency": "usd",
"description": null,
"discountable": true,
"livemode": true,
"metadata": {
},
"period": {
"start": 1507246341,
"end": 1509924741
},
"plan": {
"id": "Subscriber",
"object": "plan",
"amount": 500,
"created": 1501901993,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Subscriber",
"statement_descriptor": "WatchBuddie Stream sub",
"trial_period_days": null
},
"proration": false,
"quantity": 1,
"subscription": null,
"subscription_item": "si_1AyqWnFr5iCt1Tv7n23zDLOM",
"type": "subscription"
}
],
"total_count": 1,
"object": "list",
"url": "/v1/invoices/in_1AnV6yFr5iCt1Tv7PnqZ0EUA/lines"
},
"livemode": false,
"metadata": {
},
"next_payment_attempt": null,
"paid": true,
"period_end": 1501950408,
"period_start": 1501950408,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": "sub_00000000000000",
"subtotal": 500,
"tax": null,
"tax_percent": null,
"total": 500,
"webhooks_delivered_at": 1501950409
} } }
webhook method
def webhooks
begin
event_json = JSON.parse(request.body.read)
event_object = event_json['data']['object']
#refer event types here https://stripe.com/docs/api#event_types
case event_json['type']
when 'invoice.payment_succeeded'
#Update the total subscription total
#Send in email to the user telling them that they resubbed
logger.debug event_object['lines']['id']
end
My question is how do I get the "id": "sub_BLXcTSekdHflq5" I tried
logger.debug event_object['lines']['id']
It doesn't seem to be working what am I doing wrong? I'm sure its just a syntax thing that I am not understanding.
Thanks for all the help!
Figured it out the lines data was in a hash so you had to iterate over it. This is what I did for anyone who comes across this.
event_object['lines']['data'].each{ |i|
sub_id = i['id']
logger.debug sub_id
}
i have the being fetched, i need to read whats inside data under sources
"id": "cus_7nDkZw63KvTuy5",
"object": "customer",
"account_balance": 0,
"created": 1453839669,
"currency": "usd",
"default_source": "card_17XdJE2eZvKYlo2CBNnle4YM",
"delinquent": false,
"description": null,
"discount": null,
"email": "someone#example.com",
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
{
"id": "card_17XdJE2eZvKYlo2CBNnle4YM",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_7nDkZw63KvTuy5",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 12,
"exp_year": 2016,
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": "someone#example.com",
"tokenization_method": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_7nDkZw63KvTuy5/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_7nDkZw63KvTuy5/subscriptions"
}
}
Try this code you will get array
[[[[result objectForKey:#"sources"] objectForKey:#"data"] objectAtIndex:0] objectForKey:#"country"];
you will get US as answer.
Hi I am using swagger for documentation of my RESTful web service. wanted to know is there any way to remove the certain properties of objects from the json document response? I mean there are lots of properties that swagger gives for my method param objects and response model (e.g. notes, defaultValue, allowableValue, internalDescription etc.) that are not required for me and are null due to that the response is not much readable
For method params:
"parameters": [
{
"name": "someName1",
"description": null,
"notes": null,
"paramType": "path",
"defaultValue": null,
"allowableValues": null,
"required": true,
"allowMultiple": false,
"paramAccess": null,
"internalDescription": null,
"wrapperName": null,
"dataType": "string",
"valueTypeInternal": null
},
{
"name": "someName2",
"description": null,
"notes": null,
"paramType": "query",
"defaultValue": null,
"allowableValues": null,
"required": true,
"allowMultiple": false,
"paramAccess": null,
"internalDescription": null,
"wrapperName": null,
"dataType": "string",
"valueTypeInternal": null
}
],
-=============================================================================
For response model classes
"SomeResponseClass": {
"required": false,
"name": null,
"id": "SomeResponseClass",
"properties": {
"instanceVariable1": {
"required": false,
"name": null,
"id": null,
"properties": null,
"allowableValues": null,
"description": null,
"notes": null,
"access": null,
"default": null,
"additionalProperties": null,
"items": null,
"uniqueItems": false,
"type": "Date"
},
"instanceVariable2": {
"required": false,
"name": null,
"id": null,
"properties": null,
"allowableValues": null,
"description": null,
"notes": null,
"access": null,
"default": null,
"additionalProperties": null,
"items": null,
"uniqueItems": false,
"type": "double"
}
}
your JSON mapper is not configured to ignore null properties. You can easily address this as follows:
#Provider
#Produces(MediaType.APPLICATION_JSON)
public class JacksonJsonProvider extends JacksonJaxbJsonProvider {
private static ObjectMapper commonMapper = null;
public JacksonJsonProvider() {
if(commonMapper == null){
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
commonMapper = mapper;
}
super.setMapper(commonMapper);
}
}
Add this mapper to your scanning properties in the web.xml and the nulls will be gone.