How to check if payment sheet is open? - stripe-payments

I'm using React and I have an effect (i.e. useEffect) that tries to update the total in a paymentRequest (i.e. paymentRequest.update).
When I try to do that, stripe throws an error:
IntegrationError: You cannot update Payment Request options while the payment sheet is showing
…which make enough sense but now my issue is that I don't know how to check if the payment sheet is already open or not to prevent the update from being called.
I'm looking to do something like this:
if (!paymentSheetOpen()) {
paymentRequest.update({/* ... */});
}
How do I implement paymentSheetOpen?

I asked this question on the stripe IRC and this was the user timebox's answer:
You need to listen to/for the click and cancel events, per here: https://stripe.com/docs/js/payment_request/update

Related

Is there callback available for any RichResponse in Dialogflow

I have a dialogflow requirement to present user a payment link, on the click of which I must hang on 20 seconds (show some busy image or something) and then call on the next Intent.
So far I have been able to present a link using LinkOutSuggestion/BasicCard button. But I do not have idea that how I can make my program proceed further. I know there is a approach to have user input something like "Check Payment", but can we skip this altogether and just pass on to next intent post click of that LinkOutSuggestion or BasicCard Button?
The only way you could skip the part of the user having to input something in the chat is by using a Suggestion. These suggestions cannot be added to a card or open a link, but they do continue the conversation with the text that is used, so you could add a suggestion saying Check Payment.
The linkout suggestion or buttons on card do not support a click event or the possibility to continue the conversation.

Google Assistant - How to re-prompt if the input is invalid?

I am using Google Assistant with Node.js where I ask the user for check-in date and check-out date.
If the check-out date is later than the check-in date then I want to add a re-prompt so that the user can tell a valid date. Is there a way to force a re-prompt from the code?
The code snippet is below:
app.intent('myIntent', conv => {
// validation
const checkInDateString = conv.parameters[CHECK_IN_ARGUMENT];
const checkOutDateString = conv.parameters[CHECK_OUT_ARGUMENT];
var checkInDate = new Date(checkInDateString);
var checkOutDate = new Date(checkOutDateString);
console.log("Check-in date is: " + checkInDate.getTime());
console.log("Check-out date is: " + checkOutDate.getTime());
if (checkInDate.getTime() > checkOutDate.getTime())
{
conv.close('Pick a check-out date that is later than the check-in date!');
console.error('The check-in date must be before the check-out date!');
}
else
{
// save to db.
}
});
I don't want to close the conversation, but rather to do a re-prompt for the last question.
This is the first attempt after the check-out date failed.
and this is the second attempt:
For adding a re-prompt after checking the date, you need to handle the parameters/slots in the NodeJS code by enabling "Enable webhook call for slot filling" at the bottom of the "add intent".
With this, for every parameter required, the webhook NodeJS code will be called and you can check the validity of the parameters.
The important point will be the re-prompt. When you want to re-prompt for correct parameter, you need to set the context programmatically. The issue will be that while collecting slots, dynamic context is generated by the Dialogflow for individual parameters.
You need to identify the context associated with your date parameter and if re-prompt, set that context with lifespan 2 so as to collect the parameter again.
A better way would be to have a separate individual intent for all the parameters that you want to validate. This way you will not have to identify the dynamic context and you can play with your own context while re-prompting.
Update - using second approach
Identify the slots that require validation.
Remove them from the current intent.
Create separate intents for each slot that require validation.
Enable webhook for these intents (not for the slot as you are collecting only one).
In the webhook, if the validation fails, set the output context same as the input so as to trigger the same intent.
Respond back with re-prompt response.
You want to use conv.ask() instead of conv.close(). Using ask() will send the message in the same way but will expect the user to respond. As the name might suggest, close() does close the microphone and end the conversation.
Additionally here for simplicity, consider using contexts, as those accomplish some persistence of state.
In your example, the action can fail correctly (as it should), but also save the check-in date so the next call can run correctly with both dates. The "7th March 2018" request can also trigger the same action, but read the check-in date already saved and function correctly.

How to undo receive payment for invoice in quickbook desktop edition using qbfc sdk

I use QBFC v13 and asp.net with c#. I have create one invoice and paid some amount for this invoice, problem is that now i want to undo payment for this invoice.I try this but not working.
ITxnDel txnDelRq = RecPayrequestMsgSet.AppendTxnDelRq();
txnDelRq.TxnDelType.SetValue(ENTxnDelType.tdtReceivePayment);
txnDelRq.TxnID.SetValue(TxnId);
So if you look at the Exception, you can see that you're getting a response from QuickBooks, and it's an error:
Object 339-1507104811 specified in the request cannot be found.
What QuickBooks is telling you here is that, in your request, you referred to a specific object (the object with TxnID = 339-1507104811) and QuickBooks can not find this object.
That means one of two things. Either:
Somebody else already deleted the object
You're using an incorrect TxnID value
Did somebody else already delete the payment? You? Your program on a previous run?
Are you 100% positive you have the correct TxnID value? It should be from the ReceivePaymentAdd request you initially used to create the payment.

Alexa skill have user confirm slot values

I'm building Alexa skills using Node.js in a lambda function and can't find any tutorials on the best way to confirm the data I have in the slots. I got to the point that all slots now have data but would like to have Alexa read back the request and get a confirmation from the user before proceeding. What's the best & proper way to do this?
At first I thought to use an emit with :elicitSlot but then I would need a new slot to do this and it looks very hackish.
for example:
if(all slots have a valid value){
this.emit(':elicitSlot','confirm',"You're request is .... with data .... is this correct?");
}
if(user confirmed data is valid){
// do something
}else{
// the data was not correct get the right data
}
For the whole intent confirmation, check here. For only slot confirmation, check here.
Also, for your followup question,
can the confirmation for the skill and slots be fine tuned for example if one of the slots is something like a name and alexa knows 100% what name I said can it skip the confirmation?
Short answer - of course you can if you do not maintain the dialog. However, it's strongly discouraged to rely on that.
In order to maintain a dialog, you have to monitor dialogState attribute of the intent request, and as long as it's not in state COMPLETED send response with attribute directives as [{'type': 'Dialog.Delegate'}] to keep it flowing. You can maintain finer control of the dialog - consult this doc. Moreover, you are strongly suggested to omit outputSpeech and reprompt in those responses, otherwise Alexa gets upset. Once dialog status is COMPLETED, you get confirmationStatus (for both Intent and slots) - SUCCESS(?)/DENIED/NONE. If the confirmation is not successful. I have seen multiple matches being sent as reply. However, when successful, only the matched slot value is returned.
P.S. I have had this weird issue. When Alexa is asking for confirmation for one slot value, if I deliberately decline twice in a row, it gives up and does nothing! Although, pretty much 99% of the time Alexa was spot on.
P.P.S. Turns out 2 attempts was a hard limitation from Alexa. This is supposed to be improved in next iterations.

How to modify a Customer Refund in an After Submit User Event

After a new Customer Refund record is saved (After Submit user event) I need to communicate with an external web service and then update 2 fields in the record. When this code is executed to load the Customer Refund
var o = nlapiLoadRecord("customerrefund", 1906);
This error message is returned:
INVALID_TRANS_TYP
Transaction type specified is incorrect.
I found a list of supported records in the "Chapter 60 SuiteScript Supported Records" of SuiteScript Developer & Reference Guide which says the Customer Refund is only available in a server side script.
How should I go about updating the Customer Refund record?
Without seeing more code, it looks ok. I would double check that the internalId of 1906 is correct.
Also, if you're just submitting two fields, I would use nlapiSubmitField(), this will take less governance points and be quicker for NetSuite rather than nlapiLoadRecord / nlapiSubmitRecord.
Your code looks correct, if you are updating the current record I would recommend using below code to avoid incorrect internalid:
var o = nlapiLoadRecord("customerrefund", nlapiGetRecordId());
Also, I would recommend that if you need to update the fields, consider using before submit user event script on customer refund and you can update the fields using nlapiSetFieldValue(FIELD_ID, FIELD_VALUE). No need to submit the record in case of before submit.
If your script is deployed in the customer refund record, you can also do nlapiGetRecordType().

Resources