Update Parse.com User From Stripe Webhook

Firstly, I see that there are a few Parse / Stripe questions here, but none of them help me.

I have a mobile application that has both free and paid features. The variable is stored in the User class in Parse.com and is checked for permissions when the function starts. I would like to set up an account portal (separate for my application), so when users want to register, they are sent to their browser and can subscribe to the plan via SSL, etc.

For the account portal, I have a Wordpress site with a Stripe plugin that will run my accounts, billing, and creating forms for me.

After registering on the Wordpress website, I would like to get a webhook on Parse.com and run the function to update the User class. Ideally, this would be a catch function that changes the user to several states depending on the state of the account (that is, they will stop paying and the plan will be suspended).

My question is double:

  • What details (URL, etc.) do I need to place in the settings of my Stripe website to send all events to my Parse.com cloud code?

  • How do I get / run my function in the cloud when I receive a website from Parse.com?

I am open to criticism and retain flexibility in my implementation if you have any suggestions on how my application should work.

Thank you very much in advance.

+6
source share
2 answers

Good after some experimentation:

  • create a website in the Stripe account area using the URL: https://**APPLICATION_ID**:javascript-key=**JAVASCRIPT_KEY**@api.parse.com/1/functions/update_user

  • Your cloud code uses the same function name as the end of your URL. in my case update_user .

  • Create a test version of webhook and put this in your cloud code for testing:

Parse.Cloud.define("update_user", function(request, response) { response.success('** WEBHOOK WORKING **' + request); });

When you run the test on the lane control panel, you should see:

enter image description here

Hope this helps someone - I would be grateful for any contribution that anyone has regarding my implementation or a smooth function to trigger my update of the User class.

+5
source

Basically, I think your solution will work.

I think that using a javascript key can be a security risk if you do not check for events originating from the strip.

Your javascript keys will be present on your website. Someone can get it and call the cloud code function. I would use a master key so that you know it only from sources that you trust. They can change important billing information.

In the cloud definition definition, you can check if the primary key has been used.

 Parse.Cloud.define('stripeEvents', function (request, response) { if (request.master){ return response.success('stripeEvents - master'); } response.error('stripeEvents - must use master key');}); 
+1
source

Source: https://habr.com/ru/post/986168/


All Articles