Using Stripe webhooks with graphql-yoga and Prisma - express

I'm having some trouble finding how to intercept Stripe webhook calls in my application. I use graphql-yoga (express) and prisma.
I have to listen to payment failure calls from Stripe so I can edit the corresponding user profile.
Thanks for the help!
Stripe webhook calls look like so :
{
"created": 1326853478,
"id": "charge.expired_00000000000000",
"type": "charge.expired",
"object": "event",
"request": null,
"pending_webhooks": 1,
"data": {
"object": {
"id": "ch_00000000000000",
"object": "charge",
"amount": 100,
"captured": false,
"created": 1537153592,
"currency": "usd",
"customer": null,
"description": "My First Test Charge (created for API docs)",
"invoice": null,
"livemode": false,
"on_behalf_of": null,
"order": null,
"outcome": null,
"paid": true,
"receipt_email": null,
"receipt_number": null,
"refunded": false,
"review": null,
"shipping": null,
"source": {
"id": "card_00000000000000",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": "12919",
"address_zip_check": "pass",
"brand": "Visa",
"country": "US",
"customer": "cus_00000000000000",
"cvc_check": null,
"name": null,
"tokenization_method": null
},
"statement_descriptor": null,
"status": "succeeded",
}
}
}

Since Stripe Webhook returns a generic http POST with JSON payload, it will not format the event data according to Graphql language query.
For now, what you can do is to expose a normal REST API endpoint using Graphql-Yoga's express[0]
I have composed a working sample code you can try it out
const { GraphQLServer } = require('graphql-yoga')
const typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}
const server = new GraphQLServer({ typeDefs, resolvers, skipValidation: true })
server.express.use('/api/stripe/webhooks', (req, res) => {
// Handle your callback here !!!!
res.status(200).send();
})
server.start(() => console.log('Server is running on localhost:4000'))
Let me know if the above helps.
[0] https://github.com/prisma/graphql-yoga#how-to-eject-from-the-standard-express-setup

Related

restful api get not work,but scan can work

anybody know why restful api scan has data
http://127.0.0.1:8080/ignite?cmd=qryscanexe&pageSize=5&cacheName=contact
result
{
"successStatus": 0,
"error": null,
"sessionToken": null,
"response": {
"items": [
{
"key": {
"id": 703896957108224
},
"value": {
"mergedId": null,
"priority": 0,
"identities": [
{
"id": "7",
"type": "idCard",
"dateCreated": 1652932875433,
"lastUpdated": 1652932875433
}
],
"followerIds": [],
"contactType": "LEADER",
"dateCreated": 1652932875433,
"lastUpdated": 1652932875433
}
}
],
"last": true,
"queryId": 2,
"fieldsMetadata": [
{
"schemaName": null,
"typeName": null,
"fieldName": "key",
"fieldTypeName": null
},
{
"schemaName": null,
"typeName": null,
"fieldName": "value",
"fieldTypeName": null
}
]
}
}.
but get command no result.
http://127.0.0.1:8080/ignite?cacheName=contact&cmd=get&keyType=ContactKey&key={"id":703896957108224}
result
{
"successStatus": 0,
"affinityNodeId": "ee5e4d0d-5c91-4b9d-b68f-5dfac2f45908",
"error": null,
"sessionToken": null,
"response": null
}
By default Ignite REST supports Java built-in types for get/put operations. But it should be possible to implement a custom serialization if needed. In general it's much better to use Ignite thin clients, it's more functional than REST.

POST request failed from Postman to Jdoodle API

I have created an account on jdoodle and buy a free plan in which we can make 200 requests per days and from there I got credentials (clientId and clientSecret) for making request to their api .
I am making post request from postman to Jdoodle api. It is giving me response as unauthorized request with status code 401 in spite of valid credentials.
Giving me unauthorised request error also when i make request for checking credits used or (how many calls I have made to their api).
POST- https://api.jdoodle.com/v1/execute/
{
"clientID" : "83xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"clientSecret" : "30xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"script" : "console.log('hello')",
"language" : "nodejs",
"versionIndex" : "0"
}
Response I am getting is -
{
"error": "Unauthorized Request",
"statusCode": 401
}
POST- https://api.jdoodle.com/v1/credit-spent
{
"clientID" : "83xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"clientSecret" : "30xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
Response I am getting is -
{
"error": "Unauthorized Request",
"statusCode": 401
}
I don't know why I am getting such response inspite of all valid credentials and parameters.
Use this postman collection. Mostly it looks like your issue is with auth. make sure if client_id and secret are safely substituted.
{
"auth": null,
"event": null,
"info": {
"_postman_id": null,
"description": null,
"name": "JDoodle Compiler API.http",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"version": null
},
"item": [
{
"description": null,
"event": null,
"id": null,
"name": "Execute Program",
"protocolProfileBehavior": null,
"request": {
"auth": null,
"body": {
"disabled": null,
"file": null,
"formdata": null,
"graphql": null,
"mode": "raw",
"options": {
"language": "json"
},
"raw": "{\"clientId\": \"{{clientId}}\", \"clientSecret\": \"{{clientSecret}}\", \"script\": \"print 'hello'\", \"language\": \"python2\", \"versionIndex\": \"0\"}",
"urlencoded": null
},
"certificate": null,
"description": "Execute Program",
"header": [
{
"description": null,
"disabled": false,
"key": "content-type",
"value": "application/json"
}
],
"method": "POST",
"proxy": null,
"url": "https://api.jdoodle.com/v1/execute/"
},
"response": null,
"variable": null,
"auth": null,
"item": null
}
],
"protocolProfileBehavior": null,
"variable": [
{
"description": null,
"disabled": false,
"id": null,
"key": "baseUrl",
"name": null,
"system": null,
"type": null,
"value": "httpsDefaultParameterValue:DefaultParameterValue#DefaultParameterValue.myshopify.com/"
},
{
"description": null,
"disabled": false,
"id": null,
"key": "id",
"name": null,
"system": null,
"type": null,
"value": "<post>"
},
{
"description": null,
"disabled": false,
"id": null,
"key": "event_id",
"name": null,
"system": null,
"type": null,
"value": "<>"
}
]
}
With dothttp request is far simple and easily sharable
#name("Execute Program")
POST "https://api.jdoodle.com/v1/execute/"
json({
"clientId": "{{clientId}}",
"clientSecret": "{{clientSecret}}",
// "script": '<?php echo "hello"; ?>',
// "language": "php",
"script" :"print 'hello'",
"language": "python2",
// "stdin": "",
"versionIndex": "0"
})

Vuex store changes not reactive in components

I have a basic store for inserting and deleting from an array
state: {
assessmentTypes : []
},
mutations: {
setAssessmentTypes(state, assessmentTypes) {
assessmentTypes.forEach(assessmentType => {
state.assessmentTypes.push(assessmentType);
});
},
removeAssessmentType ( state, assessmentTypeId ) {
let assessmentTypeIndex = state.assessmentTypes.map(assessmentType => assessmentType.id).indexOf(assessmentTypeId);
state.assessmentTypes.splice(assessmentTypeIndex, 1)
}
}
I get the state assessmentTypes in computed property in one of my components.
computed:{
assessmentTypes : {
get () {
return this.$store.state.assessmentTypes;
}
}
The problem is I am looping the array in dom for listing a div, but the computed property is not reactive. When I delete or insert a new object into/from the array (through actions), the dom is not rerendering.
Object structure
{
"id": "T7pLDdjmFWAqGiuqB",
"name": "bbb",
"code": "BBB",
"properties": {
combinationOfAssessments: false,
staffCanCreateInstance: false
},
"identifyingContext": {
"semId": "2",
"batchId": "54",
"staffId": "155",
"subjectId": "966",
"subbatchId": "391"
},
"permissions": {
"hod": "1",
"staff": "1"
},
"isActive": "1",
"createdBy": null,
"createdUserName": null,
"createdByUserType": null,
"createdDate": null,
"updatedDate": null,
"updatedBy": null,
"updatedUserName": null,
"updatedByUserType": null,
"propertiesValue": null
}

Intune azure graph api to Create deviceCompliancePolicyState Returns 400 Bad Request

Call
GET https://graph.microsoft.com/beta/managedDevices/dd9615c4-9d3b-4ece-9272-34a10e8fe908/
RESPONSE
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#managedDevices/$entity",
"id": "dd9615c4-9d3b-4ece-9272-34a10e8fe908",
"userId": null,
"deviceName": "iPad Feb23",
"hardwareInformation": {
"serialNumber": null,
"totalStorageSpace": 0,
"freeStorageSpace": 0,
"imei": "",
"meid": null,
"manufacturer": null,
"model": null,
"phoneNumber": null,
"subscriberCarrier": null,
"cellularTechnology": null,
"wifiMac": null,
"operatingSystemLanguage": null,
"isSupervised": false,
"isEncrypted": false,
"isSharedDevice": false,
"sharedDeviceCachedUsers": []
},
"ownerType": "personal",
"deviceActionResults": [],
"managementState": "managed",
"enrolledDateTime": "2017-05-24T13:10:20.8964572Z",
"lastSyncDateTime": "2017-05-24T15:16:02.6465376Z",
"chassisType": "tablet",
"operatingSystem": "iOS",
"deviceType": "iPad",
"complianceState": "compliant",
"jailBroken": "False",
"managementAgents": 2,
"managementAgent": "mdm",
"osVersion": "9.3.5",
"easActivated": false,
"easDeviceId": null,
"easActivationDateTime": "0001-01-01T00:00:00Z",
"aadRegistered": null,
"enrollmentType": "userEnrollmentWithServiceAccount",
"lostModeState": "disabled",
"activationLockBypassCode": null,
"emailAddress": null,
"azureActiveDirectoryDeviceId": "00000000-0000-0000-0000-000000000000",
"deviceRegistrationState": "registered",
"deviceCategoryDisplayName": null,
"isSupervised": false,
"exchangeLastSuccessfulSyncDateTime": "0001-01-01T00:00:00Z",
"exchangeAccessState": "none",
"exchangeAccessStateReason": "none",
"remoteAssistanceSessionUrl": "",
"isEncrypted": false,
"model": null,
"manufacturer": null
}
But when i try to do post nothing seems to work ... according to the doc here https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/intune_mam_mobileappidentifierdeployment_create
it should work just fine what is the problem with this call ...?
Call
POST https://graph.microsoft.com/beta/managedDevices/dd9615c4-9d3b-4ece-9272-34a10e8fe908/deviceCompliancePolicyStates/
{
"#odata.type": "#microsoft.graph.deviceCompliancePolicyState",
"settingStates": [
{
"#odata.type": "microsoft.graph.deviceCompliancePolicySettingState",
"setting": "Setting value",
"instanceDisplayName": "Instance Display Name value",
"state": "notApplicable",
"errorCode": 9,
"errorDescription": "Error Description value",
"userPrincipalName": "User Principal Name value",
"sources": [
{
"#odata.type": "microsoft.graph.settingSource",
"id": "Id value",
"displayName": "Display Name value"
}
]
}
],
"displayName": "Display Name value",
"version": 7,
"platformType": "androidForWork",
"state": "notApplicable",
"settingCount": 12
}
RESPONSE
{
"error": {
"code": "No method match route template",
"message": "No OData route exists that match template ~/entityset/key/navigation with http verb POST for request /StatelessDeviceConfigurationFEService/managedDevices('dd9615c4-9d3b-4ece-9272-34a10e8fe908')/deviceCompliancePolicyStates.",
"innerError": {
"request-id": "544c4ee2-a6de-4203-9c30-c3e589b77713",
"date": "2017-05-24T15:48:30"
}
}
}
I'm an engineer on the Microsoft Intune team specifically working on the integration between Microsoft Graph and Microsoft Intune.
In this case it looks like there is an issue with the documentation as deviceCompliancePolicyState entity can not be created, it is read-only entity that shows the state of a device compliance policy. I will work to get the documentation corrected. If you can let me know what scenario you were trying to accomplish by creating a deviceCompliancePolicyState entity I may be able to point you in the right direction.
Hope that helps
Peter

Initializing Sony Camera API - Camera Stuck

I can't seem to be able to start taking pictures using the API. I'm able to call several informational API calls but seems like the camera is stuck. Here's what I'm doing:
Start Smart Remote Control on RX-10 M2 (latest version)
Connect to camera wifi.
Camera displays Connecting... and gets stuck there
Call http://camera_ip:/sony/camera/getEvent
Get cameraStatus: Not Readin (Full result below)
Call getAvailableCameraFunction, I get back Other Function
Call actTakePicture, I get back Not Available Now
How do I get the camera ready to start taking pictures? What am I doing wrong?
Result of getEvent:
{
"result": [
{
"type": "availableApiList",
"names": [
"getVersions",
"getMethodTypes",
"getApplicationInfo",
"getAvailableApiList",
"getEvent",
"getSupportedCameraFunction",
"startRecMode",
"stopRecMode",
"getCameraFunction",
"getAvailableCameraFunction"
]
},
{
"cameraStatus": "NotReady",
"type": "cameraStatus"
},
null,
{
"type": "liveviewStatus",
"liveviewStatus": false
},
null,
[],
[],
null,
null,
null,
[],
null,
{
"cameraFunctionCandidates": [
"Contents Transfer",
"Remote Shooting"
],
"type": "cameraFunction",
"currentCameraFunction": "Remote Shooting"
},
null,
null,
null,
null,
null,
null,
{
"postviewImageSizeCandidates": [
"2M"
],
"type": "postviewImageSize",
"currentPostviewImageSize": "2M"
},
null,
{
"shootModeCandidates": [
"still"
],
"type": "shootMode",
"currentShootMode": "still"
},
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
{
"type": "whiteBalance",
"currentColorTemperature": 0,
"checkAvailability": true,
"currentWhiteBalanceMode": ""
},
{
"type": "touchAFPosition",
"currentTouchCoordinates": [],
"currentSet": false
}
],
"id": 1
}
Ensure that you are calling "startRecMode" before calling "actTakePicture". You need to call "startRecMode" for the following cameras in order to enable the shooting functions.
NEX-5R NEX-6 NEX-5T ILCE-7 ILCE-7R ILCE-5000 DSC-HX400V DSC-HX60V ILCE-6000 DSC-RX100M3 ILCE-7S ILCE-5100 ILCE-7M2 DSC-HX90V DSC-WX500 DSC-RX100M4 DSC-RX10M2 ILCE-7RM2 ILCE-7SM2