A Python 3 module to interact with the Bluesnap API.
Project description
# bluesnap
[](https://badge.fury.io/py/bluesnap)
[](https://pypi.python.org/pypi/bluesnap/)
[](https://travis-ci.com/selectom/bluesnap)
> A Python 3 module to interact with the Bluesnap API.
Developed in [Selectom](https://www.selectom.com).
## Install
```sh
pip install bluesnap
```
## Example
```python
import logging
import math
import random
import bluesnap
from bluesnap.resources import PaymentFieldsTokenResource, VaultedShopperResource, TransactionResource, \
TransactionMetadata, VaultedShopperInfo, ShippingContactInfo, TransactionFraudInfo, BillingContactInfo, Level3Data, \
Level3DataItem
logging.basicConfig()
client = \
bluesnap.client.configure(
# Or use "live"
env="sandbox",
# Get credentials from BlueSnap
username="...",
password="...",
# Default store Id
default_store_id="...",
# Seller id
seller_id='...',
# Default currency
default_currency="usd",
# Locale
locale='en',
# Logger
logger=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-form
input('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-checks
fraudSessionId="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 want
existingVaultedShopper = vaultedShopperResource.retrieve('22823473')
print(existingVaultedShopper)
# Validate credit card set to shopper
# -----------------------------------
# Validate the vaulted shopper
validatingTransaction = 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.08
stateTaxRate = 0.17
shippingAmount = math.ceil(float(amount) * shippingRate)
stateTaxAmount = math.ceil(float(amount) * stateTaxRate)
total = amount + shippingAmount + stateTaxAmount
amount = float(amount) / 100.0
shippingAmount = float(shippingAmount) / 100.0
stateTaxAmount = float(stateTaxAmount) / 100.0
total = float(total) / 100.0
level3Data = 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 transaction
newlyCreatedTransaction = transactionResource.retrieve(newTransaction['transactionId'])
print(newlyCreatedTransaction)
# Is it valid?
newlyCreatedTransactionIsValid = (newlyCreatedTransactionTransaction['processing-info']['processing-status'] == 'SUCCESS')
print(newlyCreatedTransactionIsValid)
```
## Related projects
You might also be interested in these projects:
* [python-bluesnap](https://github.com/justyoyo/bluesnap-python): This project was forked from it, but adds Python 3 support and includes new support for Standard JSON API resources.
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/selectom/bluesnap/issues/new).
Install with:
```sh
$ virtualenv .venv -p python3
$ . .venv/bin/activate
(.venv) $ pip install -r requirements.txt
```
and run the tests with:
```sh
(.venv) $ pip install -r tests/requirements.txt
(.venv) $ nosetests tests/
```
## Author
**Alon Diamant (advance512)**
* [github/advance512](https://github.com/advance512)
* [Homepage](http://www.alondiamant.com)
[](https://badge.fury.io/py/bluesnap)
[](https://pypi.python.org/pypi/bluesnap/)
[](https://travis-ci.com/selectom/bluesnap)
> A Python 3 module to interact with the Bluesnap API.
Developed in [Selectom](https://www.selectom.com).
## Install
```sh
pip install bluesnap
```
## Example
```python
import logging
import math
import random
import bluesnap
from bluesnap.resources import PaymentFieldsTokenResource, VaultedShopperResource, TransactionResource, \
TransactionMetadata, VaultedShopperInfo, ShippingContactInfo, TransactionFraudInfo, BillingContactInfo, Level3Data, \
Level3DataItem
logging.basicConfig()
client = \
bluesnap.client.configure(
# Or use "live"
env="sandbox",
# Get credentials from BlueSnap
username="...",
password="...",
# Default store Id
default_store_id="...",
# Seller id
seller_id='...',
# Default currency
default_currency="usd",
# Locale
locale='en',
# Logger
logger=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-form
input('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-checks
fraudSessionId="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 want
existingVaultedShopper = vaultedShopperResource.retrieve('22823473')
print(existingVaultedShopper)
# Validate credit card set to shopper
# -----------------------------------
# Validate the vaulted shopper
validatingTransaction = 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.08
stateTaxRate = 0.17
shippingAmount = math.ceil(float(amount) * shippingRate)
stateTaxAmount = math.ceil(float(amount) * stateTaxRate)
total = amount + shippingAmount + stateTaxAmount
amount = float(amount) / 100.0
shippingAmount = float(shippingAmount) / 100.0
stateTaxAmount = float(stateTaxAmount) / 100.0
total = float(total) / 100.0
level3Data = 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 transaction
newlyCreatedTransaction = transactionResource.retrieve(newTransaction['transactionId'])
print(newlyCreatedTransaction)
# Is it valid?
newlyCreatedTransactionIsValid = (newlyCreatedTransactionTransaction['processing-info']['processing-status'] == 'SUCCESS')
print(newlyCreatedTransactionIsValid)
```
## Related projects
You might also be interested in these projects:
* [python-bluesnap](https://github.com/justyoyo/bluesnap-python): This project was forked from it, but adds Python 3 support and includes new support for Standard JSON API resources.
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/selectom/bluesnap/issues/new).
Install with:
```sh
$ virtualenv .venv -p python3
$ . .venv/bin/activate
(.venv) $ pip install -r requirements.txt
```
and run the tests with:
```sh
(.venv) $ pip install -r tests/requirements.txt
(.venv) $ nosetests tests/
```
## Author
**Alon Diamant (advance512)**
* [github/advance512](https://github.com/advance512)
* [Homepage](http://www.alondiamant.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bluesnap-1.2018.9.6.tar.gz
(29.5 kB
view details)
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 bluesnap-1.2018.9.6.tar.gz.
File metadata
- Download URL: bluesnap-1.2018.9.6.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
613318650c9b453100b1cd1ded8b23b0f1b9cfb52045a955cdf929aa49606f47
|
|
| MD5 |
8ee66fbd1e0757a8f378c6ba374d9162
|
|
| BLAKE2b-256 |
f59cd72cad1e8d314ebb97e405e325c4e1a9890eeb38719ece6206b1f9500a92
|
File details
Details for the file bluesnap-1.2018.9.6-py3-none-any.whl.
File metadata
- Download URL: bluesnap-1.2018.9.6-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02186ca0e9c41f20c362d26d80975386c9adb8c5298029878c7aab1305ed91ee
|
|
| MD5 |
ebc01217c7e0bc8ad1d1027c92d90039
|
|
| BLAKE2b-256 |
e153184b5c3d3b0037b8ed94d76ee5c7f4b0da20cdd2dd9075872ef66228fb57
|