Skip to main content

A Nmi library for python

Project description

NMI Gateway

This is the wklive implementation of nmi gateway, the original documentation of nmi is: https://secure.networkmerchants.com/gw/merchants/resources/integration/integration_portal.php#cv_variables

This package was build with the unique intention to make the integration with the gateway easy.

Getting started

First you need to configure GOOGLE_APPLICATION_CREDENTIALS env variable to point to your google key credentials.

GOOGLE_APPLICATION_CREDENTIALS="path/to/you/service/account/credentials.json"

Doc

The library supports the next operations:

Customer Vault

Handle customer vault operations

add-1

Create a new customer vault with the provided id (this id is then used by other methods of this library as user_id)

# import library
from wknmi.customer_vault import CustomerVault

# init CustomerVault
customerVault = CustomerVault(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg4")
# add user
customerVault.add({
    "id": "testId113233",
    "token": "00000000-000000-000000-000000000000",
    "billing_id": "",
    "billing_info":{
        "first_name": "",
        "last_name": "",
        "address1": "",
        "city": "",
        "state": "",
        "zip": "",
        "country": "",
        "phone": "",
        "email": ""
    }
    })

edit

Edit customer vault with the provided id (this id is then used by other methods of this library as user_id)

# import library
from wknmi.customer_vault import CustomerVault

# init CustomerVault
customerVault = CustomerVault(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg4")
# add user
customerVault.edit({
    "id": "testId113233",
    "billing_id": "",
    "billing_info":{
        "first_name": "",
        "last_name": "",
        "address1": "",
        "city": "",
        "state": "",
        "zip": "",
        "country": "",
        "phone": "",
        "email": ""
    }
    })

delete

Delete customer vault with the provided id (this id is then used by other methods of this library as user_id)

# import library
from wknmi.customer_vault import CustomerVault

# init CustomerVault
customerVault = CustomerVault(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg4")
# add user
customerVault.delete(id="testId113233")

Plans

Handles plan operations with the nmi api

all

Get all plans created plans in the organization

# import library
from wknmi.plans import Plans

# init
plan = Plans(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg4")

# get plans
plan.all()

id

Get plan id information

# get swzshoppingonly plan information
plan.id("swzshoppingonly")

add_month_configuration

Create a new plan using month setup

# create plan
plan.add_month_configuration({
    "custom_plan": {
        "plan_amount": "10.00",
        "plan_name": "test",
        "plan_id": "testtset",
        "month_frequency": "1",
        "day_of_month": "1",
        "plan_payments": "0"
    }
})

edit_month_configuation

Edit plan using month configuration

# edit month configuration plan
plan.edit_month_configuration({
    "custom_plan": {
        "plan_amount": "10.00",
        "plan_name": "test",
        "plan_id": "testtset",
        "month_frequency": "1",
        "day_of_month": "1",
        "plan_payments": "0"
    }
})

add_day_configuration

Create a new plan using day setup

# create a plan using day configuration
plan.add_day_configuration({
    "custom_plan": {
        "plan_amount": "10.00",
        "plan_name": "test",
        "plan_id": "testtsetts",
        "day_frequency": "1",
        "plan_payments": "0"
    }
})

edit_day_configuration

Edit a plan using day setup

# edit a plan using day configuration
plan.edit_day_configuration({
    "custom_plan": {
        "plan_amount": "20.00",
        "plan_name": "test",
        "plan_id": "testtsetts",
        "day_frequency": "1",
        "plan_payments": "0"
    }
})

Subscription

Handles subscriptions using the nmi api

add_with_custom_month_frequency_config

Assign a subscriptions to the user_id (customer vault). if total_amount is set to 0, the method will behave as a normal subscription and the user will be charged according to the custom_subscription info object. But if total_amount is set to a value greater that 0 the user will be charged by that amount

# import library
from wknmi.subscriptions import Subscriptions

# init
subsObj = Subscriptions(url="https://nmi-server-orkrbzqvda-uc.a.run.app",org="testOrg4")

# assign subscription to custumer vault
subsObj.add_with_custom_month_frequency_config({
    "userId": "1",
    "orderId": "test",
    "totalAmount": "0", # 0 for subscription without an addition sale amount
    "customSubscriptionInfo": {
        "planId": "test",
        "planAmount": "10.00",
        "planName": "test",
        "monthFrequency": "1",
        "dayOfMonth": "1",
        "planPayments": "0",
        "startDate": "20240808",
    }
})

add_with_custom_day_frequency_config

Assign a subscriptions to the user_id (customer vault). if total_amount is set to 0, the method will behave as a normal subscription and the user will be charged according to the custom_subscription info object. But if total_amount is set to a value greater that 0 the user will be charged by that amount

# assign subscription to custumer vault
subsObj.add_with_custom_day_frequency_config({
    "userId": "1",
    "org": "testOrg",
    "orderId": "testRef",
    "totalAmount": "0",# 0 for subscription without an addition sale amount
    "customSubscriptionInfo": {
        "planPayments": "15",
        "planAmount": "6",
        "dayFrequency": "1",
        "startDate": "20240808",
    }
})

Pause/Resume

Pause subscription

#pause subscription
subscription_id = "your subscription id"
pause = "true" # true to pause/false to resume
subsObj.pause(subscription_id, "true")

Cancel

Cancel a subscripion

subscription_id = "your subscription id"
result = subsObj.cancel(subscription_id)

by_user_id

Get all subscriptions of user_id

#get subscriptions of user id
user_id = "your user id"
result = subsObj.by_user_id(user_id)

subscription_id

Get subscription information base on subscription_id

#get subscriptions of user id
subscription_id = ""
result = subsObj.id(subscription_id)

Config

Handles creations of the merchants

get

Get merchant information

# import library
from wknmi.config import Config

# init
Config(url="http://127.0.0.1:8000",org="testOrg4")

# get merchant configuration
configObj.get()

update

Update merchant information

# edit merchant information
configObj.update({
    "store_id": 2342311,
    "environment_active": "sandbox",
    "org":"testOrg4",
    "production_env": {
        "token": ""
    },
    "sandbox_env": {
        "token": ""
    },
    "secret_token": "",
    "merchant_orchestrator_url":"http://",
    "merchant_id":"123",
    "merchant_signature":"123"
})

add

Create a new merchant

# add a new merchant
configObj.add({
    "store_id": 234232211,
    "environment_active": "sandbox",
    "org":"testOrg5",
    "production_env": {
        "token": "4QaH5w77U2k843fu68EuB34c4M5KJ7r3"
    },
    "sandbox_env": {
        "token": "4QaH5w77U2k843fu68EuB34c4M5KJ7r3"
    },
    "secret_token": "4QaH5w77U2k843fu68EuB34c4M5KJ7r3",
    "merchant_orchestrator_url":"http://",
    "merchant_id":"123",
    "merchant_signature":"123"
})

delete

Delete a merchant

configObj.delete("testOrg5")

Payments

Handles nmi payments

with_token

# import library
from wknmi.payment import Pay

# init
pay = Pay(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg")

# fill payment data
result = pay.with_token(
    {
        "token": "00000000-000000-000000-000000000000",
        "total": "11",
        "billingInfo": {
            "first_name": "",
            "last_name": "",
            "address1": "",
            "city": "",
            "state": "",
            "zip": "",
            "country": "",
            "phone": "",
            "email": "",
            "company": "",
            "address2": "",
            "fax": "",
            "shipping_id": "",
            "shipping_address1": "",
            "shipping_address2": "",
            "shipping_city": "",
            "shipping_country": "",
            "shipping_zip": "",
            "shipping_state": "",
            "shipping_first_name": "",
            "shipping_last_name": "",
            "shipping_phone": "",
            "shipping_email": ""
        },
    }
)

with_customer_vault

# import library
from wknmi.payment import Pay

# init
pay = Pay(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg")

# fill payment data
pay.with_customer_vault({
    "customerVault": "982f128f-8e77-4ed9-a495-1b708f79b8e2",
    "total": "11",
    "billingInfo": {
        "first_name": "",
        "last_name": "",
        "address1": "",
        "city": "",
        "state": "",
        "zip": "",
        "country": "",
        "phone": "",
        "email": "",
        "company": "",
        "address2": "",
        "fax": "",
        "shipping_id": "",
        "shipping_address1": "",
        "shipping_address2": "",
        "shipping_city": "",
        "shipping_country": "",
        "shipping_zip": "",
        "shipping_state": "",
        "shipping_first_name": "",
        "shipping_last_name": "",
        "shipping_phone": "",
        "shipping_email": ""
    },
})

refund

# import library
from wknmi.payment import Pay

# init
pay = Pay(url="https://nmi-server-orkrbzqvda-uc.a.run.app", org="testOrg")

# fill payment data
pay.refund("9192863564")

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

wkl-nmi-0.0.12.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

wkl_nmi-0.0.12-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file wkl-nmi-0.0.12.tar.gz.

File metadata

  • Download URL: wkl-nmi-0.0.12.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for wkl-nmi-0.0.12.tar.gz
Algorithm Hash digest
SHA256 e1508a08d219d3ace7c24e822b657b902bb6e3cbb874ff64a07a806881b84c8f
MD5 37e29224abaaf9327cb18ea42ab7813d
BLAKE2b-256 32e04701dcdcdf391ae96f503f18e49406fcaf2179d7bd78a3c98f34c25ddeeb

See more details on using hashes here.

File details

Details for the file wkl_nmi-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: wkl_nmi-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for wkl_nmi-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 6e6d7583c1bfbb889f9fbe144ca688c7490c97fb57fe18b3b37145f8acb13f30
MD5 e7f66c1eb6998746c3dc2e25b91b308f
BLAKE2b-256 2af85b47b38e408aeb3648849dfb7d8413d92047badb056a149d1fef317a59b8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page