Package: yuansfer
Yuansfer Python SDKYuansfer APIRequirementsThe SDK supports the following versions of Python:Python 3 versions 3.4 and laterInstallationInstall the latest SDK using pip:pipinstallyuansfer==3.0.4UsageFirst 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:fromyuansfer.clientimportClient# Create an instance of the API Client# and initialize it with the sandbox credentialsclient=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 callapi_online=client.online# Set request payloadparams={'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 requestresult=api_online.secure_pay(params)# Call the success method to see if the call succeededifresult.is_success():# Check if the request is successfulifresult.body['ret_code']=='000100':# The body property is the resposne from YuansferyuansferResponse=result.body['result']print(yuansferResponse)else:print(result.body['ret_msg'])# Call the error method to see if the call failedelifresult.is_error():print('Error calling OnlineApi.SecurePay')errors=result.errors# An error is returned as a list of errorsforerrorinerrors:# Each error is represented as a dictionaryforkey,valueinerror.items():print(f"{key}:{value}")print("\n")### 2. Offline API# Get an instance of the Yuansfer Offline API you want callapi_offline=client.offline# Set request payloadparams={'amount':'0.01','currency':'USD','settleCurrency':'USD','reference':datetime.now}# Make a Yuansfer Instore Create Transaction QR Code requestresult=offline.instore_create_tran_qrcode(params)# Call the success method to see if the call succeededifresult.is_success():# Check if the request is successfulifresult.body['ret_code']=='000100':# The body property is the resposne from YuansferyuansferResponse=result.body['result']print(yuansferResponse)else:print(result.body['ret_msg'])# Call the error method to see if the call failedelifresult.is_error():print('Error calling OfflineApi.InstoreCreateTranQrcode')errors=result.errors# An error is returned as a list of errorsforerrorinerrors:# Each error is represented as a dictionaryforkey,valueinerror.items():print(f"{key}:{value}")print("\n")### 3. Mobile API# Get an instance of the Yuansfer Mobile API you want callapi_mobile=client.mobile# Set request payloadparams={'amount':'0.01','currency':'USD','settleCurrency':'USD','reference':datetime.now,'vendor':'alipay','terminal':'APP'}# Make a Yuansfer Mobile Prepay requestresult=api_mobile.mobile_prepay(params)# Call the success method to see if the call succeededifresult.is_success():# Check if the request is successfulifresult.body['ret_code']=='000100':# The body property is the resposne from YuansferyuansferResponse=result.body['result']print(yuansferResponse)else:print(result.body['ret_msg'])# Call the error method to see if the call failedelifresult.is_error():print('Error calling MobileApi.MobilePrepay')errors=result.errors# An error is returned as a list of errorsforerrorinerrors:# Each error is represented as a dictionaryforkey,valueinerror.items():print(f"{key}:{value}")print("\n")### 4. Data Search API# Get an instance of the Yuansfer Data Search API you want callapi_data_search=client.data_search# Set request payloadparams={"transactionNo":"297553638301777927"}# Make a Yuansfer Transaction Query requestresult=api_data_search.tran_query(params)# Call the success method to see if the call succeededifresult.is_success():# Check if the request is successfulifresult.body['ret_code']=='000100':# The body property is the resposne from YuansferyuansferResponse=result.body['result']print(yuansferResponse)else:print(result.body['ret_msg'])# Call the error method to see if the call failedelifresult.is_error():print('Error calling DataSearchApi.TranQuery')errors=result.errors# An error is returned as a list of errorsforerrorinerrors:# Each error is represented as a dictionaryforkey,valueinerror.items():print(f"{key}:{value}")print("\n")### 5. PayPal Subscription API# Get an instance of the Pockyt Data Search API you want callapi_recurring=client.recurring## Set request payload# Declare PayPal Billing Cycle ObjectpaypalBillingCycle=PayPalBillingCycle()paypalBillingCycle.sequence=1paypalBillingCycle.tenure_type="REGULAR"paypalBillingCycle.total_cycles=999paypalBillingCycle.frequency=PayPalBillingCycleFrequency()paypalBillingCycle.frequency.interval_count=1paypalBillingCycle.frequency.interval_unit="MONTH"paypalBillingCycle.pricing_scheme=PayPalBillingCyclePricingScheme()paypalBillingCycle.pricing_scheme.fixed_price=PayPalBillingCycleAmount()paypalBillingCycle.pricing_scheme.fixed_price.value=20paypalBillingCycle.pricing_scheme.fixed_price.currency_code="USD"# Declare PayPal Payment Preferences ObjectpaypalPaymentPreferences=PayPalPaymentPreferences()paypalPaymentPreferences.auto_bill_outstanding=TruepaypalPaymentPreferences.setup_fee=PayPalPaymentPreferencesSetUpFee()paypalPaymentPreferences.setup_fee.value=20paypalPaymentPreferences.setup_fee.currency_code="USD"paypalPaymentPreferences.setup_fee_failure_action="CONTINUE"paypalPaymentPreferences.Payment_failure_threshold=3# Declare PayPal Taxes ObjectpaypalTaxes=PayPalTaxes()paypalTaxes.percentage="10"paypalTaxes.inclusive=True# Declare PayPal Product Schema ObjectpayPalProductSchema=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 requestresult=api_recurring.paypal_subscription(params)# Call the success method to see if the call succeededifresult.is_success():# Check if the request is successfulifresult.body['ret_code']=='000100':# The body property is the response from PockytyuansferResponse=result.body['result']print(yuansferResponse)else:print(result.body['ret_msg'])# Call the error method to see if the call failedelifresult.is_error():print('Error calling RecurringApi.PayPal_Subscription')errors=result.errors# An error is returned as a list of errorsforerrorinerrors:# Each error is represented as a dictionaryforkey,valueinerror.items():print(f"{key}:{value}")print("\n")