Stripe API创建SKU

时间:2019-05-21 10:49:52

标签: php curl hash stripe-payments sku

我需要通过Stripe API创建SKU。

问题出在库存字段中。 Stripe api响应为:

class User():

    def userNum(self):

        self.user_num = int(input("Put a 4-digit number"))
        while len(str(self.user_num)) != 4:
            self.user_num = int(input("Invalid number. Put a 4-digit number:"))

我的php代码是:

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.5/unittest/__main__.py", line 18, in <module>
    main(module=None)
  File "/usr/lib/python3.5/unittest/main.py", line 94, in __init__
    self.runTests()
  File "/usr/lib/python3.5/unittest/main.py", line 255, in runTests
    self.result = testRunner.run(self.test)
  File "/usr/lib/python3.5/unittest/runner.py", line 176, in run
    test(result)
  File "/usr/lib/python3.5/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.5/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/lib/python3.5/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.5/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/lib/python3.5/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.5/unittest/suite.py", line 122, in run
    test(result)
  File "/usr/lib/python3.5/unittest/case.py", line 648, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3.5/unittest/case.py", line 600, in run
    testMethod()
  File "/usr/lib/python3.5/unittest/mock.py", line 1157, in patched
    return func(*args, **keywargs)
  File "/home/cristian/venvs/EB/test_work1.py", line 15, in test_userNum
    self.assertEqual(self.userNum(), "Invalid number. Put a 4-digit number:")
  File "/home/cristian/venvs/EB/work1.py", line 15, in userNum
    self.user_num = int(input("Invalid number. Put a 4-digit number:""))
  File "/usr/lib/python3.5/unittest/mock.py", line 916, in __call__
    _mock_self._mock_check_sig(*args, **kwargs)
KeyboardInterrupt

在Stripe api文档中,清单是哈希类型字段。 我没有运气尝试过json_encode()。 也许问题出在发送数组而不是散列。 在$ sku数组中,库存字段也是一个嵌套的关联数组。 也许问题也在那里。

是否可以发送包含清单的CURLOPT_POSTFIELDS以便条带接受它?

编辑: 在Stripe仪表板中,我可以看到我的请求:

'error' => [
    'message' => 'Invalid hash',
    'param' => 'inventory',
    'type' => 'invalid_request_error'
]

“库存”字段没有数据,而是“数组”。

1 个答案:

答案 0 :(得分:1)

尝试了许多可能的解决方案后,我找到了答案:

$post_array = http_build_query($sku);

并且知道stripe接受带有嵌套清单数组的$ sku数组。

值得注意的是,stripe在请求中不接受JSON。

请求必须经过网址编码。