与Bluesnap API交互的Python3模块。

bluesnap的Python项目详细描述


蓝色睡眠

PyPI versionPyPI pyversionsBuild Status

A Python 3 module to interact with the Bluesnap API.

Mayple中开发。

安装

pip install bluesnap

示例

importloggingimportmathimportrandomimportbluesnapfrombluesnap.resourcesimportPaymentFieldsTokenResource,VaultedShopperResource,TransactionResource, \
    TransactionMetadata,VaultedShopperInfo,ShippingContactInfo,TransactionFraudInfo,BillingContactInfo,Level3Data, \
    Level3DataItemlogging.basicConfig()client= \
    bluesnap.client.configure(# Or use "live"env="sandbox",# Get credentials from BlueSnapusername="...",password="...",# Default store Iddefault_store_id="...",# Seller idseller_id='...',# Default currencydefault_currency="usd",# Localelocale='en',# Loggerlogger=logging.root)print(client.endpoint_url)print(bluesnap.client.default_user_agent())print(client.currency)print(client.store_id)paymentFieldsTokenResource=PaymentFieldsTokenResource()vaultedShopperResource=VaultedShopperResource()transactionResource=TransactionResource()# Create a token# --------------tokenId=paymentFieldsTokenResource.create()print(tokenId)# Use it in your frontend: https://developers.bluesnap.com/docs/build-a-forminput('Press enter to continue...')# Create vaulted shopper# ----------------------billingContactInfo=BillingContactInfo(firstName="Credit Card",lastName="Owner",personalIdentificationNumber="1234123123",address1="5 Somewhere",city="Tel Aviv",country="il",zip="123456")shippingContactInfo=ShippingContactInfo(firstName="Package",lastName="Receiver",address1="18 Otherplace",city="Ramat Gan",country="il",zip="123123")transactionFraudInfo=TransactionFraudInfo(# Have a look here: https://developers.bluesnap.com/docs/fraud-prevention#section-device-data-checksfraudSessionId="12345678123456781234567812345678",shippingContactInfo=shippingContactInfo,)vaultedShopperInfo=VaultedShopperInfo(firstName="Customer Name",lastName="for Invoicing",companyName="Company LTD",personalIdentificationNumber="123123123",shopperCurrency="USD",softDescriptor="AppearInCreditCard",descriptorPhoneNumber="+972-1231-123123",merchantShopperId="12345",address="More Place 4",city="Givatayim",country="IL",zip="123123",email="customer@email.com",phone="+972-123123123",shippingContactInfo=shippingContactInfo,transactionFraudInfo=transactionFraudInfo,)vaultedShopper=vaultedShopperResource.createFromPaymentFieldsToken(vaultedShopperInfo=vaultedShopperInfo,paymentFieldsTokenId=tokenId,billingContactInfo=billingContactInfo)print(vaultedShopper)vaultedShopperId=vaultedShopper['vaultedShopperId']# Retrieve again, if you wantexistingVaultedShopper=vaultedShopperResource.retrieve('22823473')print(existingVaultedShopper)# Validate credit card set to shopper# -----------------------------------# Validate the vaulted shoppervalidatingTransaction=transactionResource.auth(vaultedShopperId=vaultedShopperId,amount='0',currency='USD',)print(validatingTransaction)vaultedShopperIsValid=validatingTransaction['processingInfo']['processingStatus']=='success'print("vaultedShopperIsValid:",vaultedShopperIsValid)# Create a transaction# --------------------amount=random.randint(100,10000)shippingRate=0.08stateTaxRate=0.17shippingAmount=math.ceil(float(amount)*shippingRate)stateTaxAmount=math.ceil(float(amount)*stateTaxRate)total=amount+shippingAmount+stateTaxAmountamount=float(amount)/100.0shippingAmount=float(shippingAmount)/100.0stateTaxAmount=float(stateTaxAmount)/100.0total=float(total)/100.0level3Data=Level3Data(customerReferenceNumber="12345234234",salesTaxAmount=str(stateTaxRate),freightAmount=str(shippingAmount),dutyAmount="0",level3DataItems=[Level3DataItem(description="Item description",lineItemTotal=str(amount),commodityCode="96345345",grossNetIndicator="N",productCode="123123123123",itemQuantity="1",unitCost="1",unitOfMeasure="USD")])newTransaction=transactionResource.authCapture(vaultedShopperId=22823473,amount=total,currency='USD',level3Data=level3Data,transactionMetadataObjectList=[TransactionMetadata(value=f'{amount}',key='amount',description='Amount'),TransactionMetadata(value=f'{shippingAmount}',key='shippingAmount',description='Shipping Amount'),TransactionMetadata(value=f'{stateTaxAmount}',key='stateTaxAmount',description='State Tax Amount')])print(newTransaction)# Retrieve a transactionnewlyCreatedTransaction=transactionResource.retrieve(newTransaction['transactionId'])print(newlyCreatedTransaction)# Is it valid?newlyCreatedTransactionIsValid=(newlyCreatedTransactionTransaction['processing-info']['processing-status']=='SUCCESS')print(newlyCreatedTransactionIsValid)

相关项目

您也可能对这些项目感兴趣:

  • python-bluesnap:这个项目是从它派生出来的,但是添加了python 3支持,并包含了对标准json api资源的新支持。

贡献

拉请求和星星总是受欢迎的。对于错误和功能请求,please create an issue

安装时使用:

$ virtualenv .venv -p python3
$ . .venv/bin/activate
(.venv) $ pip install -r requirements.txt

并使用以下命令运行测试:

(.venv) $ pip install -r tests/requirements.txt
(.venv) $ nosetests tests/

作者

alon diamant(高级512)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Intellij通过方法中的包查找用法   java中VS代码和打包命名的问题   将java CMS功能集成到具有高度动态内容的网站(Lucene/Mysql/Nosql)的策略   oracle的java类强制转换异常。jdbc。驾驶员OracleConnection   字节码向JVM添加上指令   如何在抽象类中执行java方法?   java是否可以在apache访问日志中排除指定的GET参数?(作者:W7开发环境)   java如何获取已安装音频播放器的列表?   尝试向HS学生展示如何使用Java访问MS数据库   使用正则表达式java对给定行中的特定字符串进行计数   java JOOQ Select查询中的Select计数   方法Java,如何从二维双精度数组中找到特定值?   获取图像URL的java正则表达式   java在切换到新的窗口驱动程序后找不到元素