收入怪兽api的python包装器
rmsdk的Python项目详细描述
这是一个python sdk,它映射了open api的一些restful方法。 记录在Revenue Monster Open API Documentation上。
支持的API
- 客户端凭据(身份验证)
- 与商家相关的API
- 存储
- 用户
- 支付(快速支付qr)
- 付款(交易qr)
- 忠诚
- 代金券
用法
本节介绍sdk的基本用法。详细用法 各个模块在 examples 文件夹。
包含clientID,clientSecret的dictionary, environment和privateKey(私钥路径)应为 作为参数传入。RMSDK类的对象将是 实例化。此sdk中包含的所有模块将在 实例化的对象。
例如,要使用存储模块,只需
response = client.module.methodName(*args)
身份验证
验证sdk
from rmsdk import RMSDK client = RMSDK(configs={ "environment": "sandbox", # or production "clientID": "client-id", "clientSecret": "client-secret", "privateKey": "path-to-private-key" }) accessToken, refreshToken = client.accessToken, client.refreshToken
生成客户端凭据
使用获取刷新令牌和访问令牌(2小时后过期) 提供了clientid和clientsecret。
client = Auth({ "environment": "sandbox", # or production "clientID": "client-id", "clientSecret": "client-secret", "privateKey": "path-to-private-key" }) accessToken, refreshToken = client.clientCredentials()
生成刷新令牌
使用提供的获取新的访问令牌(2小时后过期) clientid和clientsecret(建议计划运行此功能 每少于2小时),以避免过期的访问令牌 错误。
accessToken, refreshToken = client.getRefreshToken(refreshToken)
商户
获取商户资料
result = client.merchant.getMerchantProfile(accessToken)
获取商户订阅
result = client.merchant.getMerchantSubcriptions(accessToken)
存储
获取商店列表
result = client.store.getStores(accessToken)
按ID获取存储
result = client.store.getStoreByID(accessToken, storeID)
创建存储
result = client.store.createStore(accessToken, { "name": "Test store", "addressLine1": "Earth", "addressLine2": "Mars", "postCode": "10001", "city": "Petaling Jaya", "state": "Selangor", "country": "Malaysia", "countryCode": "60", "phoneNumber": "377334080" })
更新商店
result = client.store.updateStore(accessToken, storeID, { "name": "Test store", "addressLine1": "Earth", "addressLine2": "Mars", "postCode": "10001", "city": "Petaling Jaya", "state": "Selangor", "country": "Malaysia", "countryCode": "60", "phoneNumber": "377334080" })
删除存储
result = client.store.deleteStore(accessToken, storeID)
用户
获取用户配置文件
result = client.user.getUserProfile(accessToken)
付款(quickpay qr)
快速支付
result = client.quickPay.quickPay(accessToken, { "authCode": "1234567890", "order": { "amount": 100, "currencyType":"MYR", "id":"1312331232", "title":"title", "detail":"desc", "additonalData":"API Test" }, "ipAddress": "8.8.8.8", "terminalId": "19382734937293999", "storeId": "6170506694335521334" })
退款
result = client.quickPay.refund(accessToken, { "transactionId": "190109042809010428940037", "refund": { "type": "FULL", "currencyType": "MYR", "amount": 100, }, "reason": "test" })
反向
result = client.quickPay.reverse(accessToken, { "orderId": "111222333" })
获取所有事务
result = client.quickPay.getAllTransactions(accessToken)
按ID获取事务
result = client.quickPay.getTransactionByID(accessToken, transactionID)
按订单ID获取交易
result = client.quickPay.getTransactionByOrder(accessToken, orderID)
获取每日结算报告
result = client.quickPay.dailySettlementReport(accessToken, { "date": "2019-01-09", "method": "WECHATPAY", "region": "MALAYSIA", "sequence": 1 })
付款(交易qr)
创建事务
result = client.transaction.createTransaction(accessToken, { "amount": 100, "currencyType": "MYR", "expiry": { "type": "PERMANENT" }, "isPreFillAmount": True, "method": ['WECHATPAY'], "order": { "details": "Test", "title": "Title" }, "redirectUrl": 'https://www.revenuemonster.com', "storeId": '1981039839353524638', "type": 'DYNAMIC', })
获取事务
result = client.transaction.getTransaction(accessToken)
按代码获取事务
result = client.transaction.getTransactionByCode(accessToken, qrCode)
按代码获取事务列表
result = client.transaction.getTransactionByCode(accessToken, qrCode)
忠诚度
给予忠诚积分
result = client.loyalty.giveLoyaltyPoint(accessToken, { "point": 100, "type": "ID", "memberId": "7765269777796630408", "countryCode": "60", "phoneNumber": "172826990" })
获得忠诚会员
result = client.loyalty.getLoyaltyMember(accessToken, memberID)
获取忠诚会员列表
result = client.loyalty.getLoyaltyMembers(accessToken)
获取点历史
获取会员的忠诚度积分历史记录
result = client.loyalty.getLoyaltyMemberPointHistory(accessToken, memberID)
优惠券
第五期奥彻
result = client.voucher.issueVoucher(accessToken, batchKey)
作废凭证
result = client.voucher.voidVoucher(accessToken, voucherCode)
按代码获取凭证
result = client.voucher.getVoucherByCode(accessToken, voucherCode)
获取凭证批次
result = client.voucher.getVoucherBatches(accessToken)