【问题标题】:Is there a way to enter dollars/cents via DTMF?有没有办法通过 DTMF 输入美元/美分?
【发布时间】:2020-06-11 12:43:46
【问题描述】:

我目前正在使用此流程开发电话付费系统:

  • <Gather> 客户在我们这里的帐号
  • <Gather>支付金额
  • <Pay> - 前 2 个 <Gather>s 作为变量传递给 Stripe

我遇到的问题是收取金额。有没有办法将金额从单个字符串转换为十进制字符串?

例如。 12300 变为 123.00

欢迎所有建议,因为当前的工作理论是添加第三个 <Gather> 只是为了美分,但从 UX/UI 的角度来看这感觉很麻烦。

【问题讨论】:

    标签: twilio twilio-twiml twilio-programmable-voice


    【解决方案1】:

    我编辑了这个答案,因为我成功地完成了这个。

    我用 STUDIO 和 FUNCTIONS 做到了。

    提示调用者使用星号键 () 作为小数输入金额。例如,要输入 $5.43,他们应该输入 543,然后按 #。

    然后我将收集到的数字作为参数发送到 FUNCTION 小部件中,方法是插入“amount”作为 KEY,{{widgets.gather_1.digits}} 作为参数的 VALUE。

    我写了以下函数:

    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}}

    您的付款应使用美元和美分处理。

    让我知道这是否有效。如果您需要我的工作室流程的屏幕截图,请告诉我。

    添加:

    如果有人想用作模板(有人要求),这是一个示例流程

    打开一个空白的 Studio 流程。

    在“配置”选项卡下的触发器小部件中,单击“显示流JSON”删除所有以前的代码并将代码粘贴到下面并保存。

    您的流程应该会生成。

    然后创建函数。 JSON之后的代码和说明如下。

    请注意:虽然流程中可能会弹出一个功能,但您将无法访问它,并且必须在您的帐户下创建它。

    {
      "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
      }
    }
    

    使用此代码创建一个函数:

    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}}

    【讨论】:

    • 我会把代码贴出来,我看不懂你的完整信息请回复评论
    猜你喜欢
    • 2022-11-01
    • 2011-04-13
    • 2019-10-12
    • 2021-03-31
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多