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({
    "user_id": "1",
    "order_id": "test",
    "total_amount": "0", # 0 for subscription without an addition sale amount
    "custom_subscription_info": {
        "plan_id": "test",
        "plan_amount": "10.00",
        "plan_name": "test",
        "month_frequency": "1",
        "day_of_month": "1",
        "plan_payments": "0"
    }
})

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({
    "user_id": "1",
    "org": "testOrg",
    "order_id": "testRef",
    "total_amount": "0",# 0 for subscription without an addition sale amount
    "custom_subscription_info": {
        "plan_payments": "15",
        "plan_amount": "6",
        "day_frequency": "1"
    }
})

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)

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.9.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

wkl_nmi-0.0.9-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wkl-nmi-0.0.9.tar.gz
  • Upload date:
  • Size: 9.9 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.9.tar.gz
Algorithm Hash digest
SHA256 268d89769a2154da006cc9933ec36a96bb7b5ac9333fef272d6a713d4627f6d4
MD5 3d62a1515a9943f2d467d804868088a5
BLAKE2b-256 e3af6c80a00fc91c117f5ce88330ca72e06abaf367db806bc02563c6fc5566fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wkl_nmi-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b17e782307c35e41edeafb9e9d25b6452b6aee30a3e46fdd3fec2e06bc0e1ca5
MD5 626fa82720c8ccf456f13d667aa78b1f
BLAKE2b-256 65770458f6fb95327c7ff411c910698ff1a54130e3b4f1a40707e8e23bee401e

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