1

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

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

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

例如。12300变成123.00

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

4

1 回答 1

0

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

我用 STUDIO 和 FUNCTIONS 做到了。

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

然后我将收集到的数字作为参数发送到 FUNCTION 小部件中,方法是插入“金额”作为 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>我插入{{widget.function_1.body}}AMOUNT 字段的小部件中。

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

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

添加:

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

打开一个空白的 Studio 流程。

在“config”选项卡下的触发器小部件中,单击“SHOW FLOW 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}}

于 2020-06-15T19:09:27.463 回答