问题描述
我目前正在通过以下流程在电话付费系统中工作:
I'm currently working on a pay-by-phone system with this flow:
-
<Gather>
客户在我们的帐号 -
<Gather>
应付金额 -
<Pay>
-前2个<Gather>
作为变量传递给Stripe
<Gather>
customer's account number with us<Gather>
amount to pay<Pay>
- with the previous 2<Gather>
s passed as variables to Stripe
我遇到的问题是收取款项.有没有办法将金额从单个字符串转换为十进制字符串?
The issue I am having is collecting the amount. Is there a way to convert the amount from a single string to a decimal string?
例如12300
变为123.00
欢迎所有建议,因为当前的工作原理是仅为美分添加第三个<Gather>
,但是从UX/UI的角度来看这很麻烦.
All suggestions welcome as the current working theory is to add a third <Gather>
just for the cents but this feels cumbersome from a UX/UI perspective.
推荐答案
我成功完成了此答案,因此我对此答案进行了编辑.
I edited this answer, since I was successful in accomplishing this.
我是用STUDIO和FUNCTIONS完成的.
I did it with STUDIO and FUNCTIONS.
使用星号()作为小数点提示呼叫者输入金额.例如,要输入$ 5.43,则应输入5 43,然后按#.
Prompt the caller to enter the amount using star key () as a decimal. For example to enter $5.43 they should enter 543 and then press #.
然后,我将收集的数字插入到FUNCTION小部件中,并通过在其中插入金额"将它们作为参数发送出去.作为键,{{widgets.gather_1.digits}}
作为参数的值.
then I took the gathered digits and sent them out as a parameter in the FUNCTION widget by inserting "amount" as the KEY and {{widgets.gather_1.digits}}
as the VALUE of the parameter.
我编写了以下函数:
exports.handler = function(context, event, callback) {
const rawamount = event.amount;
const decimalamount = rawamount.replace("*",".");
const response = decimalamount;
callback(null, response);
};
然后在<pay>
小部件中,在AMOUNT字段中插入{{widget.function_1.body}}
.
then in the <pay>
widget I inserted {{widget.function_1.body}}
in the AMOUNT field.
您的付款应以美元和美分处理.
Your payment should process with dollars and cents.
让我知道这是否有效.如果您需要我的工作室流程的屏幕截图,请告诉我.
Let me know if this worked. If you need screenshots of my studio flow let me know.
添加:
如果有人想用作模板(有人要求),这是示例流程
Here is a sample flow if someone wants to use as a template (someone requested it)
打开一个空白的Studio流程.
Open a blank Studio flow.
在触发器小部件中的"config"下标签上点击"SHOW FLOW JSON";删除所有以前的代码,然后将代码粘贴到内部并保存.
In the trigger widget under "config" tab click on "SHOW FLOW JSON" delete all previous code and paste code below inside and save.
您的流量应该会生成.
然后创建函数. JSON之后的以下代码和说明.
Then create function. Code and instructions below after JSON.
请注意:尽管功能可能会在流程中弹出,但您将无法访问它,而必须在您的帐户下创建它.
PLEASE NOTE: though a function may pop up in the flow, you won't be able to access it, and will have to create it under your account.
{
"description": "A New Flow",
"states": [
{
"name": "Trigger",
"type": "trigger",
"transitions": [
{
"event": "incomingMessage"
},
{
"next": "gather_1",
"event": "incomingCall"
},
{
"event": "incomingRequest"
}
],
"properties": {
"offset": {
"x": 0,
"y": 0
}
}
},
{
"name": "gather_1",
"type": "gather-input-on-call",
"transitions": [
{
"next": "function_1",
"event": "keypress"
},
{
"event": "speech"
},
{
"event": "timeout"
}
],
"properties": {
"voice": "man",
"speech_timeout": "auto",
"offset": {
"x": 30,
"y": 270
},
"loop": 1,
"finish_on_key": "#",
"say": "Please enter an amount, then press pound. To enter with cents use the star key. for example to enter $6.25 press six star two five.",
"language": "en-US",
"stop_gather": true,
"gather_language": "en",
"profanity_filter": "true",
"timeout": 5
}
},
{
"name": "function_1",
"type": "run-function",
"transitions": [
{
"next": "say_play_2",
"event": "success"
},
{
"event": "fail"
}
],
"properties": {
"offset": {
"x": -60,
"y": 530
},
"parameters": [
{
"value": "{{widgets.gather_1.Digits}}",
"key": "amount"
}
],
"url": "https://charcoal-sloth-2579.twil.io/insert-decimal"
}
},
{
"name": "say_play_2",
"type": "say-play",
"transitions": [
{
"next": "pay_1",
"event": "audioComplete"
}
],
"properties": {
"voice": "man",
"offset": {
"x": -59,
"y": 839
},
"loop": 1,
"say": "You entered ${{widgets.function_1.body}}",
"language": "en-US"
}
},
{
"name": "pay_1",
"type": "capture-payments",
"transitions": [
{
"next": "say_play_3",
"event": "success"
},
{
"next": "say_play_4",
"event": "maxFailedAttempts"
},
{
"next": "say_play_4",
"event": "providerError"
},
{
"next": "say_play_4",
"event": "payInterrupted"
},
{
"next": "say_play_4",
"event": "hangup"
},
{
"next": "say_play_4",
"event": "validationError"
}
],
"properties": {
"security_code": true,
"offset": {
"x": -70,
"y": 1140
},
"max_attempts": 2,
"payment_connector": "Stripe_Connector",
"payment_amount": "{{widgets.function_1.body}}",
"currency": "usd",
"language": "en-US",
"postal_code": "false",
"payment_token_type": "one-time",
"timeout": 5,
"valid_card_types": [
"visa",
"master-card",
"amex",
"discover"
]
}
},
{
"name": "say_play_3",
"type": "say-play",
"transitions": [
{
"event": "audioComplete"
}
],
"properties": {
"voice": "man",
"offset": {
"x": -185,
"y": 1433
},
"loop": 1,
"say": "Your payment ${{widgets.function_1.body}}was successful, Thank you.",
"language": "en-US"
}
},
{
"name": "say_play_4",
"type": "say-play",
"transitions": [
{
"event": "audioComplete"
}
],
"properties": {
"voice": "man",
"offset": {
"x": 190,
"y": 1456
},
"loop": 1,
"say": "There was an error with your payment. Goodbye!",
"language": "en-US"
}
}
],
"initial_state": "Trigger",
"flags": {
"allow_concurrent_calls": true
}
}
使用以下代码创建函数:
Create a function with this code:
exports.handler = function(context, event, callback) {
const amount = event.amount;
const convert = amount.replace('*', '.');
callback(null, convert);
};
确保在流程中检查函数小部件是否已选择正确的函数,并插入以下参数KEY:amount VALUE: {{widgets.YOUR_GATHER_WIDGET NAME.body}}
Make sure in the flow you check that the function widget has the right function selected and that you insert the following parameter KEY:amount VALUE: {{widgets.YOUR_GATHER_WIDGET NAME.body}}
这篇关于是否可以通过DTMF输入美元/美分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!