一些 Ping++ 对象支持加入用户指定的 metadata
参数。你可以使用键值对的形式来构建自己的 metadata
,例如 metadata[color] = red
,你可以在每一个 Charge、Order
等对象中加入订单的一些详情,如颜色、型号等属性,在查询时获得更多信息。每一个对象的 metadata
最多可以拥有 10 个键值对,数据总长度在 1000 个 Unicode 字符以内。
同时,Ping++ 提供在 Test 模式下 Webhooks 通知异常功能:创建订单时,通过在 metadata 字段中上传 pingpp_tc 字段,来模拟 Webhooks 通知延迟以及重发。你需要针对 Webhooks 延迟以及重复发送同一通知的情况进行处理,合理优化服务端接收 Webhooks 异步通知部分的逻辑。
属性 | 描述 |
---|---|
pingpp_tc optional,string | 测试模式 Webhooks 异常功能触发值。为 "001" 时,代表模拟支付成功后,同样的异步通知将重复进行推送;为 "002" 时,代表模拟支付成功后,异步通知将延迟 5 分钟再进行推送。注:此字段仅在 Test 模式下有效,不影响 Live 环境的使用。 |
phone_number optional,string | 手机号(11位)。 |
user_id optional,string | 用户 ID,商户 App 内用户的唯一标识。 |
curl https://api.pingxx.com/v1/charges \ -u sk_test_ibbTe5jLGCi5rzfH4OqPW9KC: \ -d order_no=123456789 \ -d amount=100 \ -d app[id]=app_1Gqj58ynP0mHeX1q \ -d channel=upacp \ -d currency=cny \ -d client_ip=127.0.0.1 \ -d subject="Your Subject" \ -d body="Your Body" \ -d metadata[color]=red -d metadata[phone_number]=13918651111
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
\Pingpp\Charge::create(array(
'order_no' => '123456789',
'amount' => '100',
'app' => array('id' => 'app_1Gqj58ynP0mHeX1q'),
'channel' => 'upacp',
'currency' => 'cny',
'client_ip' => '127.0.0.1',
'subject' => 'Your Subject',
'body' => 'Your Body'
'metadata' => array(
'color'=>'red'
'phone_number'=>'13918651111'
)
));
Pingpp.apiKey = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC";
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("order_no", "123456789");
chargeParams.put("amount", 100);
Map<String, String> app = new HashMap<String, String>();
app.put("id", "app_1Gqj58ynP0mHeX1q");
chargeParams.put("app", app);
chargeParams.put("channel", "upacp");
chargeParams.put("currency", "cny");
chargeParams.put("client_ip", "127.0.0.1");
chargeParams.put("subject", "Your Subject");
chargeParams.put("body", "Your Body");
Map<String, String> initialMetadata = new HashMap<String, String>();
initialMetadata.put("color", "red");
initialMetadata.put("phone_number", "13918651111");
chargeParams.put("metadata", initialMetadata);
Charge.create(chargeParams);
require "pingpp"
Pingpp.api_key = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"
Pingpp::Charge.create(
:subject => "Your Subject",
:body => "Your Body",
:amount => 100,
:order_no => "123456789",
:channel => "upacp",
:currency => "cny",
:client_ip=> '127.0.0.1',
:app => {'id' => "app_1Gqj58ynP0mHeX1q"},
:metadata => {'color' => "red"},
:metadata => {'phone_number' => "13918651111"}
)
var pingpp = require('pingpp')('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
pingpp.charges.create({
subject: "Your Subject",
body: "Your Body",
amount: 100,
order_no: "123456789",
channel: "upacp",
currency: "cny",
client_ip: "127.0.0.1",
app: {id: "app_1Gqj58ynP0mHeX1q"},
metadata: {
'color': 'red',
'phone_number': '13918651111'
}
}, function(err, charge) {
// 异步调用
});
ch = pingpp.Charge.create(
order_no='1234567890',
amount=100,
app=dict(id='app_1Gqj58ynP0mHeX1q'),
channel='upacp',
currency='cny',
client_ip='127.0.0.1',
subject='Your Subject',
body='Your Body',
metadata=dict(color='red'),
metadata=dict(phone_number='13918651111')
)
metadata := make(map[string]interface{})
metadata["color"] = "red",
metadata["phone_number"] = "13918651111"
params := &pingpp.ChargeParams{
Order_no: "1234567890",
App: pingpp.App{Id: "APP-ID"},
Amount: 100,
Channel: "upacp",
Currency: "cny",
Client_ip: "127.0.0.1",
Subject: "Your Subject",
Body: "Your Body",
Metadata: metadata,
}
//返回的第一个参数是 charge 对象,你需要将其转换成 json 给客户端,或者客户端接收后转换。
ch, err := charge.New(params)
Dictionary<String, Object> app = new Dictionary<String, Object>();
app.Add("id", app_1Gqj58ynP0mHeX1q);
Dictionary<String,Object> extra = new Dictionary<String,Object>();
extra.Add("color","red");
extra.Add("phone_number","13918651111");
Dictionary<String, Object> params = new Dictionary<String, Object>();
params.Add("amount", 100);
params.Add("currency", "cny");
params.Add("subject", "Your Subject");
params.Add("body", "Your Body");
params.Add("order_no", "123456789");
params.Add("channel", "upacp");
params.Add("client_ip", "127.0.0.1");
params.Add("app", app);
params.Add("extra", extra);
try {
//发起交易请求
Charge ch = Charge.create(params);
Console.WriteLine(ch);
} catch (Exception e) {
Console.WriteLine(e.Message.ToString());
}
{ "id": "ch_Hm5uTSifDOuTy9iLeLPSurrD", "object": "charge", "created": 1410775686, "livemode": true, "paid": false, "refunded": false, "app": "app_1Gqj58ynP0mHeX1q", "channel": "upacp", "order_no": "123456789", "client_ip": "127.0.0.1", "amount": 100, "amount_settle": 0, "currency": "cny", "subject": "Your Subject", "body": "Your Body", "time_expire": 1410779286, "time_settle": null, "transaction_no": null, "refunds": { "object": "list", "url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds", "has_more": false, "data": [] }, "amount_refunded": 0, "failure_code": null, "failure_msg": null, "metadata": { "color": "red", "phone_number": "13918651111" }, "credential": { "object": "credential", "upacp": { "tn": "201409151808060000000", "mode": "01" } }, "description": null }
{
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}
com.pingplusplus.model.Charge JSON: {
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}
#<Pingpp::Charge id=ch_Hm5uTSifDOuTy9iLeLPSurrD> JSON: {
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"extra":{},
"time_paid": null,
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}
{
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}
{
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}
{
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}
{
"id": "ch_Hm5uTSifDOuTy9iLeLPSurrD",
"object": "charge",
"created": 1410775686,
"livemode": true,
"paid": false,
"refunded": false,
"app": "app_1Gqj58ynP0mHeX1q",
"channel": "upacp",
"order_no": "123456789",
"client_ip": "127.0.0.1",
"amount": 100,
"amount_settle": 0,
"currency": "cny",
"subject": "Your Subject",
"body": "Your Body",
"time_expire": 1410779286,
"time_settle": null,
"transaction_no": null,
"refunds": {
"object": "list",
"url": "/v1/charges/ch_Hm5uTSifDOuTy9iLeLPSurrD/refunds",
"has_more": false,
"data": []
},
"amount_refunded": 0,
"failure_code": null,
"failure_msg": null,
"metadata": {
"color": "red",
"phone_number": "13918651111"
},
"credential": {
"object": "credential",
"upacp": {
"tn": "201409151808060000000",
"mode": "01"
}
},
"description": null
}