Use Yuansfer SDK to manage and run business including payment, refund, customer
Project description
Yuansfer Python SDK
Requirements
The SDK supports the following versions of Python:
- Python 3 versions 3.4 and later
Installation
Install the latest SDK using pip:
pip install yuansfer==3.0.4
Usage
First time with Yuansfer? Here’s how to get started:
- Create a Yuansfer Sandbox account. If you don’t have one already, sign up for a sandbox account.
Now let’s call your first Yuansfer API. Create a python new file, and copy the following code into that file:
from yuansfer.client import Client
# Create an instance of the API Client
# and initialize it with the sandbox credentials
client = Client(
environment='sandbox',
merchantNo='{{REPLACE_MERCHANT_NUMBER}}',
storeNo='{{REPLACE_STORE_NUMBER}}',
token='{{REPLACE_TOKEN}}'
)
### 1. Online API
# Get an instance of the Yuansfer Online API you want call
api_online = client.online
# Set request payload
params = {
'amount':'0.01',
'currency':'USD',
'settleCurrency':'USD',
'vendor':'alipay',
'terminal':'ONLINE',
'reference': datetime.now,
'ipnUrl':"http://zk-tys.yunkeguan.com/ttest/test",
'callbackUrl':"http://zk-tys.yunkeguan.com/ttest/test",
'description':'descrip',
'note':'note'
}
# Make a Yuansfer Secure Pay request
result = api_online.secure_pay(params)
# Call the success method to see if the call succeeded
if result.is_success():
# Check if the request is successful
if result.body['ret_code'] == '000100':
# The body property is the resposne from Yuansfer
yuansferResponse = result.body['result']
print(yuansferResponse)
else:
print(result.body['ret_msg'])
# Call the error method to see if the call failed
elif result.is_error():
print('Error calling OnlineApi.SecurePay')
errors = result.errors
# An error is returned as a list of errors
for error in errors:
# Each error is represented as a dictionary
for key, value in error.items():
print(f"{key} : {value}")
print("\n")
### 2. Offline API
# Get an instance of the Yuansfer Offline API you want call
api_offline = client.offline
# Set request payload
params = {
'amount':'0.01',
'currency':'USD',
'settleCurrency':'USD',
'reference': datetime.now
}
# Make a Yuansfer Instore Create Transaction QR Code request
result = offline.instore_create_tran_qrcode(params)
# Call the success method to see if the call succeeded
if result.is_success():
# Check if the request is successful
if result.body['ret_code'] == '000100':
# The body property is the resposne from Yuansfer
yuansferResponse = result.body['result']
print(yuansferResponse)
else:
print(result.body['ret_msg'])
# Call the error method to see if the call failed
elif result.is_error():
print('Error calling OfflineApi.InstoreCreateTranQrcode')
errors = result.errors
# An error is returned as a list of errors
for error in errors:
# Each error is represented as a dictionary
for key, value in error.items():
print(f"{key} : {value}")
print("\n")
### 3. Mobile API
# Get an instance of the Yuansfer Mobile API you want call
api_mobile = client.mobile
# Set request payload
params = {
'amount':'0.01',
'currency':'USD',
'settleCurrency':'USD',
'reference': datetime.now,
'vendor':'alipay',
'terminal':'APP'
}
# Make a Yuansfer Mobile Prepay request
result = api_mobile.mobile_prepay(params)
# Call the success method to see if the call succeeded
if result.is_success():
# Check if the request is successful
if result.body['ret_code'] == '000100':
# The body property is the resposne from Yuansfer
yuansferResponse = result.body['result']
print(yuansferResponse)
else:
print(result.body['ret_msg'])
# Call the error method to see if the call failed
elif result.is_error():
print('Error calling MobileApi.MobilePrepay')
errors = result.errors
# An error is returned as a list of errors
for error in errors:
# Each error is represented as a dictionary
for key, value in error.items():
print(f"{key} : {value}")
print("\n")
### 4. Data Search API
# Get an instance of the Yuansfer Data Search API you want call
api_data_search = client.data_search
# Set request payload
params = {
"transactionNo": "297553638301777927"
}
# Make a Yuansfer Transaction Query request
result = api_data_search.tran_query(params)
# Call the success method to see if the call succeeded
if result.is_success():
# Check if the request is successful
if result.body['ret_code'] == '000100':
# The body property is the resposne from Yuansfer
yuansferResponse = result.body['result']
print(yuansferResponse)
else:
print(result.body['ret_msg'])
# Call the error method to see if the call failed
elif result.is_error():
print('Error calling DataSearchApi.TranQuery')
errors = result.errors
# An error is returned as a list of errors
for error in errors:
# Each error is represented as a dictionary
for key, value in error.items():
print(f"{key} : {value}")
print("\n")
### 5. PayPal Subscription API
# Get an instance of the Pockyt Data Search API you want call
api_recurring = client.recurring
## Set request payload
# Declare PayPal Billing Cycle Object
paypalBillingCycle = PayPalBillingCycle()
paypalBillingCycle.sequence = 1
paypalBillingCycle.tenure_type = "REGULAR"
paypalBillingCycle.total_cycles = 999
paypalBillingCycle.frequency = PayPalBillingCycleFrequency()
paypalBillingCycle.frequency.interval_count = 1
paypalBillingCycle.frequency.interval_unit = "MONTH"
paypalBillingCycle.pricing_scheme = PayPalBillingCyclePricingScheme()
paypalBillingCycle.pricing_scheme.fixed_price = PayPalBillingCycleAmount()
paypalBillingCycle.pricing_scheme.fixed_price.value = 20
paypalBillingCycle.pricing_scheme.fixed_price.currency_code = "USD"
# Declare PayPal Payment Preferences Object
paypalPaymentPreferences = PayPalPaymentPreferences()
paypalPaymentPreferences.auto_bill_outstanding = True
paypalPaymentPreferences.setup_fee = PayPalPaymentPreferencesSetUpFee()
paypalPaymentPreferences.setup_fee.value = 20
paypalPaymentPreferences.setup_fee.currency_code = "USD"
paypalPaymentPreferences.setup_fee_failure_action = "CONTINUE"
paypalPaymentPreferences.Payment_failure_threshold = 3
# Declare PayPal Taxes Object
paypalTaxes = PayPalTaxes()
paypalTaxes.percentage = "10"
paypalTaxes.inclusive = True
# Declare PayPal Product Schema Object
payPalProductSchema = PayPalProductSchema()
payPalProductSchema.type = "SERVICE"
payPalProductSchema.category = "SOFTWARE"
params = {
"clientId": "<MerchantPayPalClientID>",
"secret": "<MerchantPayPalSecretID>",
'amount': "100",
"productName": "descriptive name for product test",
"planName": "descriptive name for plan test",
"planDescription": "detailed description for plan",
"requestIdProduct": "unique Id for create product request_,
"requestIdPlan": "unique Id for create plan request",
"frequency": "MONTH",
"billingCycles": json.dumps([paypalBillingCycle]
),
"paymentPreferences": json.dumps(
paypalPaymentPreferences
),
"taxes": json.dumps(
paypalTaxes
),
"productSchema": json.dumps(payPalProductSchema)
}
# Make a Pockyt PayPal Subscription request
result = api_recurring.paypal_subscription(params)
# Call the success method to see if the call succeeded
if result.is_success():
# Check if the request is successful
if result.body['ret_code'] == '000100':
# The body property is the response from Pockyt
yuansferResponse = result.body['result']
print(yuansferResponse)
else:
print(result.body['ret_msg'])
# Call the error method to see if the call failed
elif result.is_error():
print('Error calling RecurringApi.PayPal_Subscription')
errors = result.errors
# An error is returned as a list of errors
for error in errors:
# Each error is represented as a dictionary
for key, value in error.items():
print(f"{key} : {value}")
print("\n")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yuansfer-3.0.4.tar.gz.
File metadata
- Download URL: yuansfer-3.0.4.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.0.1 keyring/23.0.1 rfc3986/1.4.0 colorama/0.4.4 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b9142c7f30e859372ee22f619f8f8ae44c110a48aa361494b85b2168edea3ff
|
|
| MD5 |
edc911e08f1c1589cf655eb434e08dd1
|
|
| BLAKE2b-256 |
b69294941cc7cdbd56927c2a67d2d3fcc78e338c0de67014a37ce457bc0e5349
|
File details
Details for the file yuansfer-3.0.4-py3-none-any.whl.
File metadata
- Download URL: yuansfer-3.0.4-py3-none-any.whl
- Upload date:
- Size: 41.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.60.0 importlib-metadata/4.0.1 keyring/23.0.1 rfc3986/1.4.0 colorama/0.4.4 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3e54e81e6d61c339d08d16122e14feee0c3af4b3296a112ed4c6c7bb44dc2dc
|
|
| MD5 |
0a039e98013cf13bf21f1a3f124a2d34
|
|
| BLAKE2b-256 |
0711a4c593f24c70cb60d4202e39c254d58d9030292ced8ae139ba22176e69fc
|