# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    meta_query = {"field": "name", "has": "reza"}

    meta_query = {"field": "price", "gt": "1200000"}

    invoices = pod_billing.get_invoice_list_by_metadata(meta_query,
                                                        sc_api_key=SC_API_KEY,
                                                        sc_voucher_hash=[])
    print("Invoices :\n", invoices)
    print("Total :", pod_billing.total_items())
    # OUTPUT
    # Invoices :
    # [
    #   {
    #     "id": 59678,
    #     "totalAmountWithoutDiscount": 44500,
    #     "delegationAmount": 0,
    #     "totalAmount": 44500,
    #     "payableAmount": 48505,
    #     "vat": 4005,
    #     "issuanceDate": 1578481916475,
    #     "deliveryDate": 1582144200000,
    #     "billNumber": "Py_56555977",
Beispiel #2
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    invoice_id = 123456

    if pod_billing.cancel_invoice(invoice_id,
                                  sc_api_key=SC_API_KEY,
                                  sc_voucher_hash=SC_VOUCHER_HASH):
        print("Invoice canceled")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #3
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type="production")

    params = {"sc_api_key": SC_API_KEY, "sc_voucher_hash": []}
    products = [{
        "productId": 4565,
        "price": 1000,
        "quantity": 1,
        "productDescription": "محصول یک"
    }]
    user_id = 123456
    invoice = pod_billing.create_pre_invoice(user_id=user_id,
                                             products=products,
                                             guild_code="API_GUILD",
                                             redirect_url="http://localhost",
                                             **params)
    print("Invoice :\n", invoice)

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #4
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 32157

    payment_link = pod_billing.get_invoice_payment_link(
        invoice_id=invoice_id,
        call_url="http://localhost/webhook.php",
        redirect_url="http://localhost/callback.php")

    print(payment_link)
    # OUTPUT
    # https://sandbox.pod.ir:1033/v1/pbc/payInvoiceByUniqueNumber/?uniqueNumber=6a8419e0de989b8f&gateway=PEP

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #5
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException, InvalidDataException
from examples.config import *
from pod_billing import PodBilling
from random import randint

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    preferred_tax_rate = 0.10

    bill_number = "Py_reduce_{}".format(randint(1, 100000000))
    customer_invoice = [{
        "productId": 0,
        "price": 500,
        "quantity": 2,
        "description": "محصول اول - مشتری"
    }, {
        "productId": 0,
        "price": 300,
        "quantity": 1,
        "description": "محصول دوم - مشتری"
    }]

    main_invoice = {
        "invoiceItemVOs": [{
            "productId": 0,
            "price": 350,
            "quantity": 2,
            "description": "محصول اول - کسب و کار مالک فاکتور"
Beispiel #6
0
# coding=utf-8
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    params = {
        'isPayed': False,
        # 'isClosed': False,
        # 'isWaiting': True,
        'isCanceled': False,
        'fromDate': '1398/06/01 13:00:00',
        'toDate': '1398/06/02 17:00:00',
    }

    invoices = pod_billing.get_invoice_list(page=1, **params)
    print("Invoices :\n", invoices)
    # for invoice in invoices:
    #     print(invoice['id'])
    print("Total Invoice :", pod_billing.total_items())

    invoices = pod_billing.get_invoice_list(page=1)
    print("Invoices :\n", invoices)
    print("Total Invoice :", pod_billing.total_items())
    # OUTPUT
    # Invoices :
    #  [
    #   {
    #     "id": 32157,
# coding=utf-8
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    params = {
        "lastNRows": 0,  # تعداد ردیف های مورد نظر در خروجی فایل
        "fromDate":
        "1396/12/01 01:30:00",  # از تاریخ به صورت شمسی و فرمت yyyy/mm/dd hh:ii:ss
        "toDate":
        "1398/12/29 10:20:20",  # تا تاریخ به صورت شمسی و فرمت yyyy/mm/dd hh:ii:ss

        # # Optional Params
        # "guildCode": "",  # کد صنف
        # "id": "",   #
        # "billNumber": "",  # شماره قبض که به تنهایی با آن می توان جستجو نمود
        # "uniqueNumber": "",  # شماره کد شده ی قبض که به تنهایی با آن می توان جستجو نمود
        # "trackerId": "",  # کد رهگیری
        # "isCanceled": False,  # وضعیت کنسلی فاکتور , True or False
        # "isPayed": False,  # وضعیت پرداختی فاکتور , True or False
        # "isClosed": False,  # وضعیت بسته بودن فاکتور , True or False
        # "isWaiting": False,  # وضعیت در انتظار پرداخت بودن فاکتور , True or False
        # "referenceNumber": "",  # شماره ارجاع ثبت شده در فاکتور
        # "userId": "",  # شناسه کاربری مشتری فاکتور
        # "query": "",  # عبارت دلخواه مورد جستجو
        # "productIdList": [],  # لیست آرایه ای از شماره محصولات
        # "callbackUrl": "",  # آدرس فراخوانی پس از اتمام تولید گزارش
        # "sc_voucher_hash": [],     # لیست کد های تخفیف سرویس کال
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 123456

    if pod_billing.send_invoice_payment_sms(invoice_id=invoice_id):
        print("Invoice Payed")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #9
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    unique_number = "f6b6e624e4696d41"

    payment_link = pod_billing.get_pay_invoice_by_unique_number_link(
        unique_number=unique_number,
        call_url="http://localhost/webhook.php",
        redirect_url="http://localhost/callback.php")

    print(payment_link)
    # OUTPUT
    # https://sandbox.pod.ir:1033/v1/pbc/payInvoiceByUniqueNumber/?uniqueNumber=f6b6e624e4696d41&gateway=PEP

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
class TestPodVoucher(unittest.TestCase):
    __slots__ = ("__voucher", "__billing")

    def setUp(self):
        self.__voucher = PodVoucher(api_token=API_TOKEN, server_type=SERVER_MODE)
        self.__billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    def test_1_define_credit_voucher(self):
        vouchers = [{
            "name": "کد اعتبار 1 ریالی تست پایتون",
            "amount": 1,
            "count": 1,
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است "
        }]
        expire_date = "1420/12/01"
        result = self.__voucher.define_credit_voucher(vouchers=vouchers, guild_code=GUILD_CODE, expire_date=expire_date)
        self.assertIsInstance(result, list, msg="define credit voucher (all params) : check instance")
        self.assertEqual(len(result), 1, msg="define credit voucher (all params) : check len")

    @staticmethod
    def __generate_random_voucher(prefix=""):
        return "{}{}".format(prefix, randrange(1000, 2000000))

    def test_1_define_credit_voucher_all_params(self):
        vouchers = [{
            "name": "کد اعتبار 1 ریالی تست پایتون",
            "amount": 1,
            "count": 2,
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("CREDIT-"), self.__generate_random_voucher("CREDIT-")]
        }, {
            "name": "کد اعتبار 2 ریالی تست پایتون",
            "amount": 2,
            "count": 1,
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("CREDIT-")]
        }]
        expire_date = "1420/12/01"
        result = self.__voucher.define_credit_voucher(vouchers=vouchers, guild_code=GUILD_CODE, expire_date=expire_date,
                                                      limited_consumer_id=USER_ID, currency_code="IRR")
        self.assertIsInstance(result, list, msg="define credit voucher (all params) : check instance")
        self.assertEqual(len(result), 3, msg="define credit voucher (all params) : check len")

    def test_1_define_credit_voucher_invalid_hash_length(self):
        vouchers = [{
            "name": "کد اعتبار 1 ریالی تست پایتون",
            "amount": 1,
            "count": 3,  # changed
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("CREDIT-"), self.__generate_random_voucher("CREDIT-")]
        }, {
            "name": "کد اعتبار 2 ریالی تست پایتون",
            "amount": 2,
            "count": 1,
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("CREDIT-")]
        }]
        expire_date = "1420/12/01"

        with self.assertRaises(InvalidDataException, msg="define credit voucher : invalid hash length"):
            self.__voucher.define_credit_voucher(vouchers=vouchers, guild_code=GUILD_CODE, expire_date=expire_date,
                                                 limited_consumer_id=USER_ID, currency_code="IRR")

    def test_1_define_credit_voucher_validation_error(self):
        vouchers = [{
            "name": "کد اعتبار 1 ریالی تست پایتون",
            "amount": "1",  # should be int
            "count": "3",  # should be int
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است "
        }, {
            "name": "کد اعتبار 1 ریالی تست پایتون",
            "amount": "1",  # should be int
            "count": "1",  # should be int
            "description": "این کد اعتبار به صورت تستی و با پایتون ثبت شده است "
        }]
        expire_date = "1420-12-01"  # correct format yyyy/mm/dd
        limited_consumer_id = "123"  # should be int
        with self.assertRaises(InvalidDataException, msg="define credit voucher : validation error"):
            self.__voucher.define_credit_voucher(vouchers=vouchers, guild_code=GUILD_CODE, expire_date=expire_date,
                                                 limited_consumer_id=limited_consumer_id, currency_code="IRR")

    def test_1_define_credit_voucher_required_params(self):
        with self.assertRaises(TypeError, msg="define credit voucher : required params"):
            self.__voucher.define_credit_voucher()

    def test_2_define_discount_amount_voucher(self):
        vouchers = [{
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": 1,
            "count": 2,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است "
        }, {
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": 1,
            "count": 1,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است "
        }]
        expire_date = "1420/12/01"
        result = self.__voucher.define_discount_amount_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                               expire_date=expire_date)

        self.assertIsInstance(result, list, msg="define discount amount voucher (all params) : check instance")
        self.assertEqual(len(result), 3, msg="define discount amount voucher (all params) : check len")

    def test_2_define_discount_amount_voucher_all_params(self):
        vouchers = [{
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": 1,
            "count": 2,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS1-"), self.__generate_random_voucher("DIS1-")]
        }, {
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": 1,
            "count": 1,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS2-")]
        }]
        expire_date = "1420/12/01"
        product_list = PRODUCT_IDs
        dealer_business_id_list = DEALER_BUSINESS_IDs
        result = self.__voucher.define_discount_amount_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                               expire_date=expire_date, limited_consumer_id=USER_ID,
                                                               currency_code="IRR", product_id=product_list,
                                                               dealer_business_id=dealer_business_id_list)

        self.assertIsInstance(result, list, msg="define discount amount voucher (all params) : check instance")
        self.assertEqual(len(result), 3, msg="define discount amount voucher (all params) : check len")

    def test_2_define_discount_amount_voucher_invalid_hash_len(self):
        vouchers = [{
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": 1,
            "count": 3,  # changed
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS1-"), self.__generate_random_voucher("DIS1-")]
        }, {
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": 1,
            "count": 1,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS2-")]
        }]
        expire_date = "1420/11/01"
        with self.assertRaises(InvalidDataException, msg="define discount amount voucher : invalid hash len"):
            self.__voucher.define_discount_amount_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                          expire_date=expire_date, limited_consumer_id=USER_ID,
                                                          currency_code="IRR")

    def test_2_define_discount_amount_voucher_validation_error(self):
        vouchers = [{
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": "1",  # should be int
            "count": "3",  # should be int
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS1-"), self.__generate_random_voucher("DIS1-")]
        }, {
            "name": "کد تخفیف 1 ریالی تست پایتون",
            "amount": "1",  # should be int
            "count": "1",  # should be int
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS2-")]
        }]
        expire_date = "1420-11-01"  # correct format yyyy/mm/dd
        with self.assertRaises(InvalidDataException, msg="define discount amount voucher : validation error"):
            self.__voucher.define_discount_amount_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                          expire_date=expire_date, limited_consumer_id=USER_ID,
                                                          currency_code="IRR")

    def test_2_define_discount_amount_voucher_required_params(self):
        with self.assertRaises(TypeError, msg="define discount amount voucher : required params"):
            self.__voucher.define_discount_amount_voucher()

    def test_3_define_discount_percentage_voucher(self):
        vouchers = [{
            "name": "کد تخفیف 1 درصدی تست پایتون",
            "discountPercentage": 1,
            "amount": 100,
            "count": 2,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است "
        }, {
            "name": "کد تخفیف 2 درصدی تست پایتون",
            "discountPercentage": 2,
            "amount": 200,
            "count": 1,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است "
        }]
        expire_date = "1420/12/01"
        discount_type = PodVoucher.DISCOUNT_TYPE_ONE_TIME_INVOICE
        result = self.__voucher.define_discount_percentage_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                                   expire_date=expire_date, discount_type=discount_type)

        self.assertIsInstance(result, list, msg="define discount percentage voucher (all params) : check instance")
        self.assertEqual(len(result), 3, msg="define discount percentage voucher (all params) : check len")

    def test_3_define_discount_percentage_voucher_all_params(self):
        vouchers = [{
            "name": "کد تخفیف 1 درصدی تست پایتون",
            "discountPercentage": 1,
            "amount": 100,
            "count": 2,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS1-"), self.__generate_random_voucher("DIS1-")]
        }, {
            "name": "کد تخفیف 2 درصدی تست پایتون",
            "discountPercentage": 2,
            "amount": 200,
            "count": 1,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS2-")]
        }]
        expire_date = "1420/12/01"
        product_list = PRODUCT_IDs
        dealer_business_id_list = DEALER_BUSINESS_IDs
        discount_type = PodVoucher.DISCOUNT_TYPE_ONE_TIME_INVOICE
        result = self.__voucher.define_discount_percentage_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                                   expire_date=expire_date, limited_consumer_id=USER_ID,
                                                                   currency_code="IRR", product_id=product_list,
                                                                   dealer_business_id=dealer_business_id_list,
                                                                   discount_type=discount_type)

        self.assertIsInstance(result, list, msg="define discount percentage voucher (all params) : check instance")
        self.assertEqual(len(result), 3, msg="define discount percentage voucher (all params) : check len")

    def test_3_define_discount_percentage_voucher_invalid_hash_len(self):
        vouchers = [{
            "name": "کد تخفیف 1 درصدی تست پایتون",
            "discountPercentage": 1,
            "amount": 100,
            "count": 3,  # changed
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS1-"), self.__generate_random_voucher("DIS1-")]
        }, {
            "name": "کد تخفیف 2 درصدی تست پایتون",
            "discountPercentage": 2,
            "amount": 200,
            "count": 1,
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS2-")]
        }]
        expire_date = "1420/11/01"
        discount_type = PodVoucher.DISCOUNT_TYPE_ONE_TIME_INVOICE
        with self.assertRaises(InvalidDataException, msg="define discount percentage voucher : invalid hash len"):
            self.__voucher.define_discount_percentage_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                              expire_date=expire_date, limited_consumer_id=USER_ID,
                                                              currency_code="IRR", discount_type=discount_type)

    def test_3_define_discount_percentage_voucher_validation_error(self):
        vouchers = [{
            "name": "کد تخفیف 1 درصدی تست پایتون",
            "discountPercentage": "1",
            "amount": "100",  # should be int
            "count": "3",  # should be int
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS1-"), self.__generate_random_voucher("DIS1-")]
        }, {
            "name": "کد تخفیف 2 درصدی تست پایتون",
            "discountPercentage": "2",
            "amount": "200",  # should be int
            "count": "1",  # should be int
            "description": "این کد تخفیف به صورت تستی و با پایتون ثبت شده است ",
            "hash": [self.__generate_random_voucher("DIS2-")]
        }]
        expire_date = "1420-11-01"  # correct format yyyy/mm/dd
        discount_type = 3  # one of PodVoucher.DISCOUNT_TYPE_ONE_TIME_ITEM or PodVoucher.DISCOUNT_TYPE_ONE_TIME_INVOICE
        # or PodVoucher.DISCOUNT_TYPE_UNLIMITED

        with self.assertRaises(InvalidDataException, msg="define discount percentage voucher : validation error"):
            self.__voucher.define_discount_percentage_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                              expire_date=expire_date, limited_consumer_id=USER_ID,
                                                              currency_code="IRR", discount_type=discount_type)

    def test_3_define_discount_percentage_voucher_required_params(self):
        with self.assertRaises(TypeError, msg="define discount percentage voucher : required params"):
            self.__voucher.define_discount_percentage_voucher()

    def __get_invoice(self, **kwargs):
        kwargs["products"] = [
            {
                "productId": 0,
                "price": 50000,
                "quantity": 1,
                "productDescription": "محصول اول در پایتون"
            }
        ]
        kwargs["guild_code"] = GUILD_CODE
        kwargs["description"] = "تست اعمال کد تخفیف بر روی فاکتور بعد از صدور فاکتور - پایتون تست"
        return self.__billing.issue_invoice(**kwargs)

    def __get_voucher(self):
        vouchers = [
            {
                "name": "تخفیف 5000",
                "amount": 5000,
                "count": 1,
                "description": "Discount 5000 Rials"
            }
        ]
        voucher = self.__voucher.define_discount_amount_voucher(vouchers=vouchers, guild_code=GUILD_CODE,
                                                                expire_date="1420/12/01")
        return voucher[0]

    def test_4_apply_voucher(self):
        invoice = self.__get_invoice(postVoucherEnabled=True)
        voucher = self.__get_voucher()
        result = self.__voucher.apply_voucher(invoice_id=invoice["id"], voucher_hash=voucher["hash"])

        self.assertIsInstance(result, dict, msg="apply voucher : check instance")
        self.assertEqual(result["invoiceItemSrvs"][0]["discount"], voucher["creditAmount"],
                         msg="apply voucher : check amount")

    def test_4_apply_voucher_validation_error(self):
        with self.assertRaises(InvalidDataException, msg="apply voucher : validation error"):
            self.__voucher.apply_voucher(invoice_id="123456", voucher_hash="ABCDE")

    def test_4_apply_voucher_required_params(self):
        with self.assertRaises(TypeError, msg="apply voucher : required params"):
            self.__voucher.apply_voucher()

    def test_5_get_voucher_list(self):
        params = {
            "page": 1,
            "size": 50
        }
        result = self.__voucher.get_voucher_list(**params)
        self.assertIsInstance(result, list, msg="get voucher list : check instance")

    def test_5_get_voucher_list_all_params(self):
        params = {
            "page": 1,
            "size": 50,
            "type": PodVoucher.DISCOUNT_TYPE_ONE_TIME_INVOICE | PodVoucher.DISCOUNT_TYPE_ONE_TIME_ITEM |
                    PodVoucher.DISCOUNT_TYPE_UNLIMITED,
            "consumerId": 123456,
            "hash": "",
            "name": "",
            "guildCode": ["API_GUILD", "CLOTHING_GUILD"],
            "currencyCode": "IRR",
            "amountFrom": 0,
            "amountTo": 2000,
            "discountPercentageFrom": 5,
            "discountPercentageTo": 10,
            "expireDateFrom": "1398/12/01",
            "expireDateTo": "1399/01/01",
            "productId": [1234, 4567],
            "consumDateFrom": "1398/12/15",
            "consumDateTo": "1398/12/17",
            "usedAmountFrom": 10000,
            "usedAmountTo": 200000,
            "active": True,
            "used": False
        }

        result = self.__voucher.get_voucher_list(**params)
        self.assertIsInstance(result, list, msg="get voucher list (all params) : check instance")

    def test_5_get_voucher_list_validation_error(self):
        params = {
            "page": 1,
            "size": 50,
            "type": "1",    # should be int
            "consumerId": "123456",    # should be int
            "hash": 123,    # should be str
            "name": 123,
            "guildCode": ["API_GUILD", "CLOTHING_GUILD"],
            "currencyCode": "IRR",
            "amountFrom": 0,
            "amountTo": 2000,
            "discountPercentageFrom": 5,
            "discountPercentageTo": 10,
            "expireDateFrom": "1398-12-01",    # should be format yyyy/mm/dd
            "expireDateTo": "1399-01-01",    # should be format yyyy/mm/dd
            "productId": [1234, 4567],
            "consumDateFrom": "1398-12-15",    # should be format yyyy/mm/dd
            "consumDateTo": "1398-12-17",    # should be format yyyy/mm/dd
            "usedAmountFrom": "10000",    # should be int
            "usedAmountTo": "200000",    # should be int
            "active": "True",    # should be boolean
            "used": "False"    # should be boolean
        }
        with self.assertRaises(InvalidDataException, msg="get voucher list : validation error"):
            self.__voucher.get_voucher_list(**params)

    def test_6_activate_voucher(self):
        voucher = self.__get_voucher()

        result = self.__voucher.activate_voucher(voucher["id"])
        self.assertIsInstance(result, dict, msg="activate voucher : check instance")
        self.assertEqual(result["active"], True, msg="activate voucher : check status")

    def test_6_activate_voucher_required_params(self):
        with self.assertRaises(TypeError, msg="activate voucher : required param"):
            self.__voucher.activate_voucher()

    def test_6_activate_voucher_validation_error(self):
        with self.assertRaises(InvalidDataException, msg="activate voucher : validation error"):
            self.__voucher.activate_voucher(voucher_id="123456")

    def test_7_deactivate_voucher(self):
        voucher = self.__get_voucher()

        result = self.__voucher.deactivate_voucher(voucher["id"])
        self.assertIsInstance(result, dict, msg="deactivate voucher : check instance")
        self.assertEqual(result["active"], False, msg="deactivate voucher : check status")

    def test_7_deactivate_voucher_required_params(self):
        with self.assertRaises(TypeError, msg="deactivate voucher : required param"):
            self.__voucher.deactivate_voucher()

    def test_7_deactivate_voucher_validation_error(self):
        with self.assertRaises(InvalidDataException, msg="deactivate voucher : validation error"):
            self.__voucher.deactivate_voucher(voucher_id="123456")
 def setUp(self):
     self.__voucher = PodVoucher(api_token=API_TOKEN, server_type=SERVER_MODE)
     self.__billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
Beispiel #12
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException, InvalidDataException
from examples.config import *
from pod_billing import PodBilling
from random import randint

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    preferred_tax_rate = 0.10

    bill_number = "Py_reduce_{}".format(randint(1, 100000000))
    customer_invoice = [{
        "productId": 0,
        "price": 500,
        "quantity": 2,
        "description": "محصول اول - مشتری"
    }, {
        "productId": 0,
        "price": 300,
        "quantity": 1,
        "description": "محصول دوم - مشتری"
    }]

    main_invoice = {
        "invoiceItemVOs": [{
            "productId": 0,
            "price": 350,
            "quantity": 2,
            "description": "محصول اول - کسب و کار مالک فاکتور"
Beispiel #13
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 123456

    if pod_billing.pay_invoice_in_future(invoice_id=invoice_id, date="1398/12/01", guild_code="API_GUILD"):
        print("Invoice Payed")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 123456
    if pod_billing.verify_invoice(invoice_id=invoice_id,
                                  sc_api_key=SC_API_KEY,
                                  sc_voucher_hash=SC_VOUCHER_HASH):
        print("Invoice verified")

    bill_number = "Py123456"
    if pod_billing.verify_invoice_by_bill_number(
            bill_number=bill_number,
            sc_api_key=SC_API_KEY,
            sc_voucher_hash=SC_VOUCHER_HASH):
        print("Invoice verified")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 123456

    if pod_billing.pay_any_invoice_by_credit(invoice_id=invoice_id,
                                             wallet="PODLAND_WALLET"):
        print("Invoice Payed")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #16
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling
from random import randint

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    products = [
        {
            "productId": 0,
            "price": 4500,
            "quantity": 0.1,
            "productDescription": "محصول اول در پایتون"
        },
        {
            "productId": 0,
            "price": 8000,
            "quantity": 5,
            "productDescription": "محصول دوم در پایتون"
        }
    ]
    # invoice = pod_billing.issue_invoice(products=products, guild_code=GUILD_CODE, userId=16849)
    # print("Invoice :\n", invoice)
    # OUTPUT
    # Invoice :
    # {
    #   'id': 59529,
    #   'totalAmountWithoutDiscount': 44500,
    #   'delegationAmount': 0,
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 123456

    if pod_billing.pay_invoice(invoice_id=invoice_id):
        print("Invoice Payed")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #18
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException, InvalidDataException
from examples.config import *
from pod_billing import PodBilling
from random import randint

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)

    bill_number = "Py_{}".format(randint(1, 100000000))
    customer_invoice = [{
        "productId": 0,
        "price": 500,
        "quantity": 2,
        "description": "محصول اول - مشتری"
    }, {
        "productId": 0,
        "price": 300,
        "quantity": 1,
        "description": "محصول دوم - مشتری"
    }]

    main_invoice = {
        "invoiceItemVOs": [{
            "productId": 0,
            "price": 350,
            "quantity": 2,
            "description": "محصول اول - کسب و کار مالک فاکتور"
        }, {
            "productId": 0,
Beispiel #19
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling
from random import randint

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_items = [{
        "invoiceItemId": 64267,
        "price": 4500,
        "quantity": 1,
        "itemDescription": "محصول اول در پایتون"
    }, {
        "invoiceItemId":
        64268,
        "price":
        8000,
        "quantity":
        3,
        "itemDescription":
        "محصول دوم در پایتون - کاهش تعداد محصولات از 5 به 3"
    }]
    invoice_id = 123456

    invoice = pod_billing.reduce_invoice(invoice_id=invoice_id,
                                         items=invoice_items,
                                         preferred_tax_rate=0.09)
    print("Invoice :\n", invoice)
    # OUTPUT
Beispiel #20
0
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    invoice_id = 123456

    payment_link = pod_billing.payment.get_pay_invoice_by_wallet_link(
        invoice_id=invoice_id)
    print(payment_link)
    # OUTPUT
    # https://sandbox.pod.ir:1033/v1/pbc/payinvoice/?invoiceId=123456&tokenIssuer=1

    payment_link = pod_billing.payment.get_pay_invoice_by_wallet_link(
        invoice_id=invoice_id, call_url="http://localhost/webhook.php")
    print(payment_link)
    # OUTPUT
    # https://sandbox.pod.ir:1033/v1/pbc/payinvoice/?invoiceId=123456&tokenIssuer=1&callUri=http%3A%2F%2Flocalhost%2Fwebhook.php

    payment_link = pod_billing.payment.get_pay_invoice_by_wallet_link(
        invoice_id=invoice_id,
        call_url="http://localhost/webhook.php",
        redirect_url="http://localhost/callback.php")
    print(payment_link)
    # OUTPUT
    # https://sandbox.pod.ir:1033/v1/pbc/payinvoice/?invoiceId=123456&tokenIssuer=1&redirectUri=http%3A%2F%2Flocalhost%2Fcallback.php&callUri=http%3A%2F%2Flocalhost%2Fwebhook.php

except APIException as e:
# coding=utf-8
from __future__ import unicode_literals
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    creditor_invoice_id = 32132  # شناسه فاکتور بستانکار
    debtor_invoice_id = 59929  # شناسه فاکتور بدهکار

    if pod_billing.pay_invoice_by_invoice(
            creditor_invoice_id=creditor_invoice_id,
            debtor_invoice_id=debtor_invoice_id):
        print("Invoice Payed")

except APIException as e:
    print("API Exception\nError {}\nReference Number : {}".format(
        e.message, e.reference_number))
except PodException as e:
    print("Pod Exception: ", e.message)
Beispiel #22
0
# coding=utf-8
from pod_base import APIException, PodException
from examples.config import *
from pod_billing import PodBilling

try:
    pod_billing = PodBilling(api_token=API_TOKEN, server_type=SERVER_MODE)
    export_list = pod_billing.export.get_export_list()
    print("Export List :\n", export_list)
    print("Total Export : ", pod_billing.total_items())
    # OUTPUT
    # Export List :
    #  [
    #   {
    #       'id': 1510,
    #       'statusCode': 'EXPORT_SERVICE_STATUS_SUCCESSFUL',
    #       'creationDate': 1578382127057,
    #       'resultFile': {
    #           'id': 68083,
    #           'name': 'result-Tue Jan 07 07:29:00 UTC 2020.xlsx',
    #           'hashCode': '16f7e0000000000000004888519156',
    #           'size': 0
    #       },
    #       'service': '/nzh/biz/getInvoiceList/'
    #   },
    #   ...
    #   ]
    # Total Export :  21

    if len(export_list) > 0:
        export = export_list[0]