Can't cancel a stripe subscription through Parse API when user has more than one subscription - parse-platform

I am building site that allows users to signup for multiple subscriptions. The Parse.com / Stripe API we use allows me to create multiple subscriptions for each user. However, if a user has more than one subscription, and I attempt to cancel any of them, I get an error that the user has more than one subscription and that I must identify which subscription I am referring to. The problem is, that I do attempt to pass the subscription ID to into the API (see below) but it just seems to get ignored. Stripe clearly supports this second parameter in their API, but the Parse documentation does not show a second "subscriptionId" parameter.
The following Parse Cloud Code (which works perfectly as long as the user has only one subscription)
Parse.Cloud.define("cancelStripeSubscription", function(request, response) {
Stripe.Customers.cancelSubscription(request.params.customerId, request.params.subscriptionId, true, {
success: function(httpResponse) {
response.success("Cancellation Complete");
},
error: function(httpResponse) {
response.error("Error: " + httpResponse.message);
}
});
});
Here is the relevant Parse/Stripe Cloud Code API - https://parse.com/docs/js/api/symbols/Stripe.Customers.html#.cancelSubscription
Here is the equivalent Stripe API clearly showing a second "subscriptionId" parameter. https://stripe.com/docs/api/node#cancel_subscription
I'm hoping that the Parse/Stripe module does support multiple subscriptions.
Thanks for any help!

Unfortunately, Parse's Stripe API library is pretty old and was built against an old version of the API when only 1 subscription was possible. You'd either just have to do 1 subscription per customer or generate the web request to Stripe's API yourself not using the library.

Related

How manage payment in Google Action using Transactions API

I have developed a Google Actions Application to buy physical goods. I followed this guide: https://developers.google.com/assistant/transactions/physical/dev-guide-physical-gpay
I get the correct request / response flow:
"paymentInfo": {
"displayName": "Mastercard *ommited for security*",
"googleProvidedPaymentInstrument": {
"instrumentToken": "*ommited for security*"
},
"paymentType": "PAYMENT_CARD"
}
and finally Google returns me an instrumentToken in base64, which I think I can decode and use the ID inside it to call the Stripe API: https://stripe.com/docs/api/charges/create#create_charge-source. I tested it and it works, but seems extrange to me... Do I have to do this for every order that is successful?
My question is: Do I have to call the Stripe API myself? Is there no way Google will do it for me? In case I have to send it, should I do it when I receive the request with this field "userDecision": "ORDER_ACCEPTED" and then update the order if the payment is successful?
I have read all the official Google documentation for Actions and I cannot understand the entire flow of interaction.
As #taintedzodiac mentioned in the comment, if you use Stripe as your payment processor then you will have to use Stripe explicitly each time. This is not something that the platform will do automatically.

Post message to MS Teams channel using Graph API

I'm trying to send a message to MS Teams using Graph API. I'm passing access token (AAD token) with it but still, it's giving me below error. I have given all the required permissions in Azure API permissions.
error:
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"request-id": "53a5aaff-3d39-42ce-bdc6-74d02a756be2",
"date": "2019-12-23T06:42:27"
}
}
}
API: https://graph.microsoft.com/beta/teams/{group-id-for-Teams}/channels/{channel-id}/messages/{message-id}/replies
Oh, if this is from a bot (not clear from the original question, but clarified in your later comment) then you don't need to use the Graph API at all - there's another way to send the message using the Bot Framework tools instead. You can do this either from within your bot, or from a different application altogether. I've got a few bots where the user schedules something, like when they want a message sent, where the bot saves it to a database and I have another application (mostly I use Azure Functions right now) to send the item on that schedule.
There are some important pieces of information you need to store though, which you can get any time the users sends your bot a message - it's the information you need to store so that you know how to connect directly to that user and that conversation. It's called Pro-active Messaging, and to see how to do this, see the answer I posted at Programmtically sending a message to a bot in Microsoft Teams
If you DON'T have any conversation history with the user ever (as in they have never spoken with your bot before, and you're trying to send the first message) then it gets more complicated... Let me know if that's the case though.
Sending message to a channel using graph api is a protected api and it needs access permission from Microsoft.
Access can be requested from Microsoft access reuqest form.
Once access is given from Microsoft add graph api in api permissions of your web app, and bingo you can get the response.

Integrating Azure Bot in Web Application

We have a scenario where a user would first login to web application before starting a conversation with Azure Bot.
My question is how do we ensure bot will only allow user to ask financial questions related to his own accounts considering the bot is capable of answer questions related to financial holding of the person logged in.
Basically is there a way to pass principal object to the bot before the conversation starts. If yes how do we pass those details.
The BotFramework currently does not support single sign-on; however, the BotFramework Web Chat Development team has recommended different approaches to create a single sign-on experience and is currently working on developing a sample.
The main approach recommends piggybacking the authentication token on every outgoing message by adding it to the activity's channel data. To do this, you can create a custom middleware that appends the additional data. Take a look at the code snippet below.
const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
// The channelData submitted here is very similar to HTTP cookies and vulnerable to forgery attack.
// Make sure you use signature to protect it and verify the signature on the bot side.
// To minimize unexpected behaviors, we recommend to treat the "action" object as if it is immutable.
// We use simple-update-in package to update "action" with partial deep cloning.
action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'token'], () => token);
}
return next(action);
}
);
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
// We will use a custom version of Redux store, which we added middleware to handle backchannel messages.
store
}, document.getElementById('webchat'));
On the bot side, you can retrieve the token from the channel data and use it to make various requests. For more details on adding data to outgoing activities, take a look at this sample.
For more details regarding recommended approaches, take a look at this issue on GitHub. The Web Chat Development team is also using it to track the progress of the sample.
Hope this helps.

Luis: Access denied due to invalid subscription key

I am facing following issue when i try to update application on Luis using following request:
https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/app-id-here
header:
Ocp-Apim-Subscription-Key:paid-subscription key
body:
{
"name": "Name of luis app",
"description": "string"
}
I am getting following error:
{
"statusCode": 401,
"message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
}
I am using paid subscription from Azure portal with westus region. Still facing this issue.
However, This key works when I try to get top scoring intent using following request:
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/luis-app-id?subscription-key=subscription-key-azure&timezoneOffset=-360&q=hi
This is really weird as sunscription key works for GET request but not for PUT or POST request.
Any suggestions?
PS: I am using paid subscription key.
The (subscription) keys created with a Cognitive Service LUIS resource in Azure Portal, even when added to with Assign resource in luis.ai, can only be used for runtime queries on a defined app.
The authoring endpoints on LUIS Programmatic APIs v2.0 - to create and manage apps and their elements - can only be used with the Authoring Key available in the luis.ai portal.
More information can be found in Authoring and query prediction endpoint keys in LUIS
It looks like you have two issues you are working thru here.
First, the API you are trying to post to should read "https://[location].api.cognitive.microsoft.com/luis/api/v2.0/apps/{appId}/publish". From the looks of it, you are missing the 'publish' at the end of your API call.
Second, the paid subscription key needs to be added to your LUIS app. Can you confirm it has been added? If not, follow these steps to do so:
Click Manage => Keys and Endpoints.
Next, click 'Assign resource'.
A window will pop up allowing you to select the tenant, subscription, and the key to use.
Click OK.
Click 'Publish' to make the newly generated endpoint accessible.
Make sure you add subscription primary key value in my request and also make sure you have associated your API with the product which you used the Primary key

Can I call a Microsoft BotBuilder like calling a function?

I am trying to build a bot and use it within a chat app. I think Microsoft Bot Builder is the one for me.
I looked into its documentations and tried them in the emulator.
I noticed that in these examples, you send texts to the bot either using
"consoleconnector" or "chatconnector", as the example shows.
server.post('/api/messages', connector.listen());
// Receive messages from the user and respond by echoing each message
back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, function (session) {
session.send("You said: %s", session.message.text);
});
I don't want a new endpoint. I want to call the bot like calling a function: give the incoming message from a user and the function returns bot's response.
Is it possible? If yes, please tell me how to do it.
If it is not possible, then only way is to call it as a rest API as shown above.
In this case, do i still need "MICROSOFT_APP_ID" and "MICROSOFT_APP_PASSWORD"?
Note that, I don't want to deploy the bot to azure or aws now. I want to use it local.
Could anyone help me explain these? Thanks in advance!
The Bot Framework is built to function as an API - it takes a request and sends a response. The framework doesn't provide a callback or promise to capture the response so this approach simply wouldn't work. Take a look at the DirectLine API if you want to embed the framework within another application.
You need to use the MS App id and password for all channels apart from the Emulator. If you use DirectLine API, you will also have to pass a secret token.

Resources