pingpp 文件夹下是 Python SDK 文件,
example 文件夹里面是简单的接入示例,该示例仅供参考。
pip install pingpp
或使用 setup.py 手动安装
python setup.py install
pingpp.api_key = 'YOUR_KEY'密钥需要你自己生成,公钥请填写到 Ping++ Dashboard
设置你的私钥路径
pingpp.private_key_path = '/path/to/your_rsa_private_key.pem'ch = pingpp.Charge.create(
order_no='123456789',
channel='alipay',
amount=1,
subject='test-subject',
body='test-body',
currency='cny',
app=dict(id='APP_ID'),
client_ip='127.0.0.1'
)pingpp.Charge.retrieve('CHARGE_ID')pingpp.Charge.all()ch = pingpp.Charge.retrieve('CHARGE_ID')
re = ch.refunds.create(
amount=1,
description='Refund Description'
)ch = pingpp.Charge.retrieve('CHARGE_ID')
re = ch.refunds.retrieve('REFUND_ID')ch = pingpp.Charge.retrieve('CHARGE_ID')
res = ch.refunds.all(limit=3)pingpp.RedEnvelope.create(
order_no='123456789',
channel='wx_pub',
amount=100,
subject='Your Subject',
body='Your Body',
currency='cny',
app=dict(id='APP_ID'),
extra=dict(send_name='Send Name'),
recipient='User Openid',
description='Your Description'
)pingpp.RedEnvelope.retrieve('RED_ID')pingpp.RedEnvelope.all()pingpp.Event.retrieve('EVENT_ID')tr = pingpp.Transfer.create(
order_no='1234567890',
channel='wx_pub',
amount=100,
currency='cny',
app=dict(id='APP_ID'),
type='b2c',
recipient='User Openid',
extra=dict(user_name='User Name', force_check=False),
description='Your Description'
)pingpp.Transfer.retrieve('TRANSFER_ID')pingpp.Transfer.all()pingpp.BatchRefund.create(
"app": app_id,
"batch_no": "batchrefund20160801001",
"description": "Batch refund description.",
"charges": [
"ch_L8qn10mLmr1GS8e5OODmHaL4",
"ch_fdOmHaLmLmr1GOD4qn1dS8e5"
]
)pingpp.BatchRefund.retrieve("batchrefund20160801001")pingpp.BatchRefund.list()##订单
order_info = {
"app": app_id,
"uid": "15800973612",
"merchant_order_no": "88888888888",
"coupon":"300316082514255200000900",
"amount": "30",
"client_ip": "127.0.0.1",
"currency": "cny",
"subject": "test1",
"body": "test1body1",
"description": "test1-description",
"time_expire": int(time.time()) + 1000
}
pingpp.Order.create(**order_info)params = {
"charge_amount": 0,
"balance_amount": 10
}
pingpp.Order.pay( "order_0001", **params)pingpp.Order.cancel("2011608250000000971")pingpp.Order.retrieve("2011608250000000971")pingpp.Order.all()params = {
"description": "Your description"
}
order_refund = pingpp.OrderRefunds.create(order_id="2011611140000003181", **params)pingpp.OrderRefunds.retrieve(order_id="2011611140000003181", order_refunds_id="1234")pingpp.OrderRefunds.list(order_id="2011611140000003181")params = {
"app": app_id,
"uid": "15800973612",
"merchant_order_no": "88888888888",
"channel":"wx",
"amount": "30",
"client_ip": "127.0.0.1",
"currency": "cny",
"subject": "test1",
"body": "test1body1",
"description": "test1-description",
"time_expire": "1479266356"
}
recharge = pingpp.Recharge.create(**params)pingpp.AssetTransaction.list(app=app_id)pingpp.AssetTransaction.retrieve(app=app_id, id="assetTransaction_0001")##账户系统
request_info = {
"id": "test_user_0005", # id 唯一
"address": "address_1",
"avatar": None,
"email": None,
"gender": "MALE",
"metadata": {},
"mobile": None,
"name": "Your user name"
}
pingpp.User.create(app=app_id, **request_info)pingpp.User.list()pingpp.User.retrieve("test_user_0002", app=app_id)request_info = {
"address": "address_1",
"avatar": None,
"email": None,
"gender": "MALE",
"metadata": {},
"mobile": None,
"name": "Your user name"
}
pingpp.User.update(app=app_id,user="USER_TEST_0001", **request_info)pingpp.BalanceTransaction.retrieve(app=app_id, user="test_user_001",id="txn_14697807964587241560000001")pingpp.BalanceTransaction.list(app=app_id,user="test_user_001")pingpp.User.createBalanceTransfer(app=app_id, user="test_user_02")request_info = {
"amount": 20000,
"user_fee": 50,
"description": "test232description",
"extra": {
"card_number": "6225210207073918",
"user_name": "姓名",
"open_bank_code": "0102",
"prov": "上海",
"city": "上海"
}
}
pingpp.Withdrawal.create(user="user_id_001", **request_info)pingpp.Withdrawal.retrieve("withDrawal_0002", app=app_id, user="user_id_001")pingpp.Withdrawal.cancel("withDrawl_0002")pingpp.Withdrawal.list(user="user_id_001")params = {
"coupon_template": "300116082415452100000700",
}
pingpp.Coupon.create(user="user_test_001", **params)params = {
"coupon_template": "300116082415452100000700",
"metadata": {
"key": "value"
}
}
pingpp.Coupon.update("coupon_id_001", user="user_test_001", **params)delete_coupon = pingpp.Coupon.delete("coupon_id_001", user="user_test_001")pingpp.Coupon.retrieve("coupon_id_001", user="user_test_001")pingpp.Coupon.list(user="user_test_001")params={
"name": "25OFF",
"type": 1,
"percent_off": 25,
"amount_available": 10000,
"max_circulation": 1000,
"metadata": {
},
"expiration": null
}
pingpp.CouponTemplate.create(app=app_id, **params)pingpp.CouponTemplate.list()pingpp.CouponTemplate.retrieve("coupon_id_001", user="user_test_001")pingpp.CouponTemplate.update("COUPON_TMPL_001", **params)pingpp.CouponTemplate.delete("COUPON_TMPL_001")pingpp.CouponTemplate.retrieve_coupons(coupon_tmpl="COUPON_TMPL_001")pingpp.CouponTemplate.create_coupons(app=app_id, coupon_tmpl="COUPON_TMPL_001")req_params = {
"app": app_id,
"batch_no": "batchrefund20160801001",
"description": "Batch refund description.",
"charges": [
"ch_L8qn10mLmr1GS8e5OODmHaL4",
"ch_fdOmHaLmLmr1GOD4qn1dS8e5"
]
}
pingpp.BatchTransfer.create(**req_params)pingpp.BatchTransfer.retrieve('BATCH_0001')pingpp.BatchTransfer.list()pingpp.Statistics.retrieve(app=app_id)params = {
"withdrawals": [
"1701611150302360654",
"1701611151015078981"
]
}
pingpp.BatchWithdrawal.create(app=app_id, **params)pingpp.BatchWithdrawal.retrieve("bw_123456",app=app_id)params = {
'display_name': 'sub_app_display_name',
'user': 'test_user_031',
'metadata': {
'key': 'value'
},
'description': 'Your description'
}
sub_app = pingpp.SubApp.create(app=pingpp.app_id, **params)pingpp.SubApp.retrieve(app=pingpp.app_id, id='app_1Gqj58ynP0mHeX1q')pingpp.SubApp.delete(app=app_id, id='app_1Gqj58ynP0mHeX1q')pingpp.SubApp.list(app=pingpp.app_id)params = {
"banned_msg": None,
"channel": "alipay",
"description": "Your description",
"params": {
"alipay_account": "Your alipay Account",
"alipay_app_id": "Your Alipay App ID",
"alipay_app_public_key": "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHoOhsk4g\/6sIK5KB5V9Vvim\/tFb\nCNuJ2zVhBjp377rnWIlf0ogfW7AHW5lyPl8rwVshFdk1F1eFk4Hk9s25tp8klbJl\nkJ3\/DxZIqBc7i9j\/h75Lx\/0nKqsLophYGBGWxJGl1RgwXlbw+mXJdpXbSNxAifIv\nqNqEZwwAS7C\/rmn1AgMBAAE=\n-----END PUBLIC KEY-----",
"alipay_app_public_key_rsa2": None,
"alipay_mer_app_private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgHoOhsk4g\/6sIK5KB5V9Vvim\/tFbCNuJ2zVhBjp377rnWIlf0ogf\nW7AHW5lyPl8rwVshFdk1F1eFk4Hk9s25tp8klbJlkJ3\/DxZIqBc7i9j\/h75Lx\/0n\nKqsLophYGBGWxJGl1RgwXlbw+mXJdpXbSNxAifIvqNqEZwwAS7C\/rmn1AgMBAAEC\ngYBuV5mUaaoyXovA5J4Mj95DNj0hKMpOJkds70TBMNIhxqlsr5rVgnvSHCS8COLI\nCPdpGfT1gyCR9+kNQd+4xg6IeqDpL3CqIgtZi+qRGpVJgXW1x\/oZYzzpqD4Q0\/4U\nUmOp6Mo9bDPnYKSVgReWWNtCdKncWvBE4gbYadHXYva6FQJBALfW1SPWzA2i7fQu\ncG89pPkBQOMG\/pd8JyeBgEHOv2\/nBN9zqir\/zMMFd+EbI00A1goy1pu4IVvt+GFG\nq\/\/5ZE8CQQCp93SxpFjbB49s5F+Lvs0PR08IzfxY9eoCrd9xt4hXqmksUYcodBtu",
"alipay_mer_app_private_key_rsa2": None,
"alipay_pid": "alipay_pid",
"alipay_refund_nopwd": False,
"alipay_security_key": "alipay_security_key",
"alipay_sign_type": "rsa",
"alipay_version": 1,
"fee_rate": 80
}
}
pingpp.Channel.create(app=pingpp.app_id, sub_app_id='app_1Gqj58ynP0mHeX1q', **params)updateParams = {
'description': 'Your Channel description',
'params': {
"alipay_account": "Your alipay Account",
"alipay_app_id": "Your Alipay App ID",
"alipay_app_public_key": "-----BEGIN PUBLIC KEY-----\nMIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHoOhsk4g\/6sIK5KB5V9Vvim\/tFb\nCNuJ2zVhBjp377rnWIlf0ogfW7AHW5lyPl8rwVshFdk1F1eFk4Hk9s25tp8klbJl\nkJ3\/DxZIqBc7i9j\/h75Lx\/0nKqsLophYGBGWxJGl1RgwXlbw+mXJdpXbSNxAifIv\nqNqEZwwAS7C\/rmn1AgMBAAE=\n-----END PUBLIC KEY-----",
"alipay_app_public_key_rsa2": None,
"alipay_mer_app_private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgHoOhsk4g\/6sIK5KB5V9Vvim\/tFbCNuJ2zVhBjp377rnWIlf0ogf\nW7AHW5lyPl8rwVshFdk1F1eFk4Hk9s25tp8klbJlkJ3\/DxZIqBc7i9j\/h75Lx\/0n\nKqsLophYGBGWxJGl1RgwXlbw+mXJdpXbSNxAifIvqNqEZwwAS7C\/rmn1AgMBAAEC\ngYBuV5mUaaoyXovA5J4Mj95DNj0hKMpOJkds70TBMNIhxqlsr5rVgnvSHCS8COLI\nCPdpGfT1gyCR9+kNQd+4xg6IeqDpL3CqIgtZi+qRGpVJgXW1x\/oZYzzpqD4Q0\/4U\nUmOp6Mo9bDPnYKSVgReWWNtCdKncWvBE4gbYadHXYva6FQJBALfW1SPWzA2i7fQu\ncG89pPkBQOMG\/pd8JyeBgEHOv2\/nBN9zqir\/zMMFd+EbI00A1goy1pu4IVvt+GFG\nq\/\/5ZE8CQQCp93SxpFjbB49s5F+Lvs0PR08IzfxY9eoCrd9xt4hXqmksUYcodBtu",
"alipay_mer_app_private_key_rsa2": None,
"alipay_pid": "alipay_pid",
"alipay_refund_nopwd": False,
"alipay_security_key": "alipay_security_key",
"alipay_sign_type": "rsa",
"alipay_version": 1,
"fee_rate": 80
},
'banned': False
}
pingpp.Channel.update(app=pingpp.app_id, sub_app_id='app_1Gqj58ynP0mHeX1q', channel='alipay',
**updateParams)pingpp.Channel.delete(app=pingpp.app_id, sub_app_id='app_1Gqj58ynP0mHeX1q', channel='alipay')pingpp.Channel.retrieve(app=pingpp.app_id, sub_app_id='app_1Gqj58ynP0mHeX1q', channel='alipay')
print('retrieve sub_app channel list:', channel_list)# 创建结算账号-中国银联渠道
params = {
"channel": "unionpay",
"recipient": {
"account": "6214850266666666",
"name": "11111111",
"type": "b2c", # 转账类型。b2c:企业向个人付款,b2b:企业向企业付款。
"open_bank": "招商银行",
"open_bank_code": "0308"
}
}
pingpp.SettleAccount.create(app=pingpp.app_id, user='test_user_003', **params)
# 创建结算账号-支付宝渠道
params = {
"channel": "alipay",
"recipient": {
"account": "account@domain.com",
"name": "李四",
"type": "b2c" # 转账类型。b2c:企业向个人付款。
}
}
pingpp.SettleAccount.create(app=pingpp.app_id, user='test_user_003', **params)
# 创建结算账号-微信渠道
params = {
"channel": "wx_pub",
"recipient": {
"account": "your_open_id",
"name": "王五",
"type": "b2c", # 转账类型。b2c:企业向个人付款。
"force_check": False
}
}
pingpp.SettleAccount.create(app=pingpp.app_id, user='test_user_003', **params)pingpp.SettleAccount.retrieve(app=pingpp.app_id, user='test_user_003', settle_account_id='320117032014485200000201')pingpp.SettleAccount.delete(app=pingpp.app_id, user='test_user_003', settle_account_id='320117032014485200000201')pingpp.SettleAccount.list(app=pingpp.app_id, user='test_user_003')params = {
"ids": [
"170301124238000111",
"170301124238000211"
],
"method": "manual",
"description": "Your description"
}
pingpp.Royaltie.update(**params)pingpp.Royaltie.retrieve('410170320160900002')params = {
'page': 1,
'per_page': 15
}
pingpp.Royaltie.all(**params)params = {
"payer_app": pingpp.app_id,
"method": "unionpay",
"recipient_app": pingpp.app_id,
"created": {
"gt": 1488211200,
"lte": 1488297600
}
}
pingpp.RoyaltySettlement.create(**params)pingpp.RoyaltySettlement.retrieve(id='430170320150300001')# 更新分润结算对象-确认
pingpp.RoyaltySettlement.confirm(id='430170320150300001')
# 更新分润结算对象-取消
pingpp.RoyaltySettlement.cancel(id='430170320150300001')pingpp.RoyaltySettlement.all(**params)params = dict(
page = 1,
per_page = 15
)
pingpp.RoyaltyTransaction.all(**params)pingpp.RoyaltyTransaction.retrieve(id='440170320155300006')详细信息请参考 API 文档。