Ai
2 Star 0 Fork 0

mirrors_sourcegraph/stripe-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
paymentintent_test.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
Remi Jannel 提交于 2018-06-28 07:18 +08:00 . Add support for the PaymentIntent resource
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
)
func TestPaymentIntentSourceAction_UnmarshalJSON(t *testing.T) {
actionData := map[string]interface{}{
"type": "authorize_with_url",
"value": map[string]interface{}{
"url": "https://stripe.com",
},
}
bytes, err := json.Marshal(&actionData)
assert.NoError(t, err)
var action PaymentIntentSourceAction
err = json.Unmarshal(bytes, &action)
assert.NoError(t, err)
assert.Equal(t, PaymentIntentNextActionAuthorizeWithURL, action.Type)
assert.Equal(t, "https://stripe.com", action.Value.AuthorizeWithURL.URL)
}
func TestPaymentIntent_UnmarshalJSON(t *testing.T) {
intentData := map[string]interface{}{
"id": "pi_123",
"object": "payment_intent",
"allowed_source_types": []interface{}{
"card",
},
"charges": map[string]interface{}{
"object": "list",
"has_more": true,
"data": []map[string]interface{}{
{
"id": "ch_123",
"object": "charge",
},
{
"id": "ch_234",
"object": "charge",
},
},
},
}
bytes, err := json.Marshal(&intentData)
assert.NoError(t, err)
var intent PaymentIntent
err = json.Unmarshal(bytes, &intent)
assert.NoError(t, err)
assert.Equal(t, "pi_123", intent.ID)
assert.Equal(t, 1, len(intent.AllowedSourceTypes))
assert.Equal(t, 2, len(intent.Charges.Data))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_sourcegraph/stripe-go.git
git@gitee.com:mirrors_sourcegraph/stripe-go.git
mirrors_sourcegraph
stripe-go
stripe-go
master

搜索帮助