From 85898a7969f69dff372c614a072c9e2245efc11a Mon Sep 17 00:00:00 2001 From: Ido Widya Yudhatama Date: Mon, 5 May 2025 16:52:32 +0700 Subject: [PATCH 1/3] docs: add example how to create request with duitku library --- examples/invoice.md | 34 +++++++++++++++++++++++ examples/payment.md | 30 ++++++++++++++++++++ examples/transaction.md | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 examples/invoice.md create mode 100644 examples/payment.md create mode 100644 examples/transaction.md diff --git a/examples/invoice.md b/examples/invoice.md new file mode 100644 index 0000000..5c6d506 --- /dev/null +++ b/examples/invoice.md @@ -0,0 +1,34 @@ +# Invoice Service + +## Create Invoice + +```python +import Duitku + +from datetime import datetime + +# Initialize duitku class +duitku = Duitku.Duitku() + +# Initialize duitku client +client = duitku.client +client.merchant_code ='YOUR_MERCHANT_CODE' +client.api_key = 'YOUR_API_KEY' + +# NOTE: no need to initialize duitku class and client if you already had initialized + +# Create request body for invoice +create_invoice_req = { + "paymentAmount": 20000, + "merchantOrderId": datetime.now().strfti("%Y%m%d%H%M%S"), + "productDetails": "the best example product", + "email": "sales@example.com", + "callbackUrl": "https://example.com/callback", + "returnUrl": "https://example.com" +} + +result = duitku.invoice.create(create_invoice_req) + +# Process response body +print(response.message) +``` \ No newline at end of file diff --git a/examples/payment.md b/examples/payment.md new file mode 100644 index 0000000..74637ba --- /dev/null +++ b/examples/payment.md @@ -0,0 +1,30 @@ +# Payment Service + +## Get Payment Method + +```python +import Duitku + +from datetime import datetime + +# Initialize duitku class +duitku = Duitku.Duitku() + +# Initialize duitku client +client = duitku.client +client.merchant_code ='YOUR_MERCHANT_CODE' +client.api_key = 'YOUR_API_KEY' + +# NOTE: no need to initialize duitku class and client if you already had initialized + +# Create request body for get payment method +request_get_payment_methods = { + "amount": 10001, + "datetime": datetime.now().strftime("%Y-%m-%%H:%M:%S"), +} + +result = duitku.payment.get_methods(request_get_payment_methods) + +# Process response body +print(response.message) +``` \ No newline at end of file diff --git a/examples/transaction.md b/examples/transaction.md new file mode 100644 index 0000000..6073c2b --- /dev/null +++ b/examples/transaction.md @@ -0,0 +1,61 @@ +# Transaction Service + +## Create Transaction + +```python +import Duitku + +from datetime import datetime + +# Initialize duitku class +duitku = Duitku.Duitku() + +# Initialize duitku client +client = duitku.client +client.merchant_code ='YOUR_MERCHANT_CODE' +client.api_key = 'YOUR_API_KEY' + +# NOTE: no need to initialize duitku class and client if you already had initialized + +request_create_transaction = { + "paymentAmount": 10000, + "merchantOrderId": datetime.now().strftime("%Y%m%d%H%M%S"), + "productDetails": "test create transaction example", + "email": "sales@example.com", + "paymentMethod": "VC", + "customerVaName": "Test Transaction", + "callbackUrl": "https://example.com/callback", + "returnUrl": "https://example.com" +} + +result = duitku.transaction.create(request_create_transaction) + +# Process response body +print(result.message) +``` + +## Get Status +```python +import Duitku + +from datetime import datetime + +# Initialize duitku class +duitku = Duitku.Duitku() + +# Initialize duitku client +client = duitku.client +client.merchant_code ='YOUR_MERCHANT_CODE' +client.api_key = 'YOUR_API_KEY' + +# NOTE: no need to initialize duitku class and client if you already had initialized + +request_get_transaction = { + "merchantOrderId": "YOUR_MERCHANT_ORDER_ID" +} + +result = duitku.transaction.get_status(request_get_transaction) + +# Process response body +print(result.message) +``` \ No newline at end of file From e72bd54b2639859f2a194ecb13a8eaa9c9b48fe9 Mon Sep 17 00:00:00 2001 From: Ido Widya Yudhatama Date: Mon, 5 May 2025 16:54:00 +0700 Subject: [PATCH 2/3] docs: add fastapi example --- README.md | 6 +++ examples/fastapi/.env.example | 2 + examples/fastapi/main.py | 90 +++++++++++++++++++++++++++++++ examples/fastapi/requirements.txt | 4 ++ 4 files changed, 102 insertions(+) create mode 100644 examples/fastapi/.env.example create mode 100644 examples/fastapi/main.py create mode 100644 examples/fastapi/requirements.txt diff --git a/README.md b/README.md index cb436e0..2badf0a 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ result = self.duitku.invoice.create(create_invoice_req) print(result) ``` +## More Detailed Example +- [Invoice (Create Invoice - POP)](examples/invoice.md) +- [Payment (Get Payment Method)](examples/payment.md) +- [Transaction (Create Transaction, Get Transaction Status)](examples/transaction.md) +- [How to Write in FastAPI](examples/fastapi/main.py) + ## Support If you have a feature request or spotted a bug or a techical problem, [create an issue here](https://github.com/idoyudha/duitku-python/issues/new/choose). For other questions, please contact duitku through their live chat on your dashboard. diff --git a/examples/fastapi/.env.example b/examples/fastapi/.env.example new file mode 100644 index 0000000..40995fd --- /dev/null +++ b/examples/fastapi/.env.example @@ -0,0 +1,2 @@ +MERCHANT_CODE=EXAMPLE_MERCHANT_CODE +API_KEY=EXAMPLE_API_KEY \ No newline at end of file diff --git a/examples/fastapi/main.py b/examples/fastapi/main.py new file mode 100644 index 0000000..93552b2 --- /dev/null +++ b/examples/fastapi/main.py @@ -0,0 +1,90 @@ +from dotenv import load_dotenv +from fastapi import FastAPI +from pydantic import BaseModel + +import Duitku +import os + + +load_dotenv() + +app = FastAPI() + +# To run app in development mode, use command `fastapi dev main.py`` + +@app.get("/") +def read_root(): + return {"Hello": "Duitku Python SDK"} + +duitku = Duitku.Duitku() + +client = duitku.client +client.merchant_code = os.getenv('MERCHANT_CODE') +client.api_key = os.getenv('API_KEY') +client.environment = client.SandboxEnv + +class CreateInvoiceReq(BaseModel): + paymentAmount: int + merchantOrderId: str + productDetails: str + email: str + callbackUrl: str + returnUrl: str + +@app.post("/invoice") +def create_invoice(body: CreateInvoiceReq): + req = { + "paymentAmount": body.paymentAmount, + "merchantOrderId": body.merchantOrderId, + "productDetails": body.productDetails, + "email": body.email, + "callbackUrl": body.callbackUrl, + "returnUrl": body.returnUrl + } + result = duitku.invoice.create(req) + return result.message + +class PaymentMethodReq(BaseModel): + amount: str + datetime: str + +@app.post("/payment-method") +def get_payment_method(body: PaymentMethodReq): + req = { + "amount": body.amount, + "datetime": body.datetime + } + result = duitku.payment.get_methods(req) + return result.message + +class CreateTransactioneReq(BaseModel): + paymentAmount: int + merchantOrderId: str + productDetails: str + email: str + customerName: str + callbackUrl: str + returnUrl: str + +@app.post("/transaction") +def create_transaction(body: CreateTransactioneReq): + req = { + "paymentAmount": body.paymentAmount, + "merchantOrderId": body.merchantOrderId, + "productDetails": body.productDetails, + "email": body.email, + "paymentMethod": "VC", + "customerVaName": body.customerName, + "callbackUrl": body.callbackUrl, + "returnUrl": body.returnUrl + } + result = duitku.transaction.create(req) + return result.message + +@app.get("/transaction/{id}") +def get_transaction(id): + req = { + "merchantOrderId": id + } + result = duitku.transaction.get_status(req) + return result.message \ No newline at end of file diff --git a/examples/fastapi/requirements.txt b/examples/fastapi/requirements.txt new file mode 100644 index 0000000..9d1fe12 --- /dev/null +++ b/examples/fastapi/requirements.txt @@ -0,0 +1,4 @@ +duitku==0.2.9 +fastapi==0.115.12 +pydantic==2.11.4 +python-dotenv==1.1.0 From e221490e9ab6ec21fe6ce1b19cd3107bce160c8f Mon Sep 17 00:00:00 2001 From: Ido Widya Yudhatama Date: Mon, 5 May 2025 17:04:48 +0700 Subject: [PATCH 3/3] docs: up to version 0.2.10 --- pyproject.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 259e602..32fb4ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "Duitku" -version = "0.2.9" +version = "0.2.10" authors = [ {name = "Ido Yudhatama", email = "idowidya.yudhatama@gmail.com"}, ] diff --git a/setup.py b/setup.py index 2ef3497..2540e82 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name="Duitku", - version="0.2.9", + version="0.2.10", description="Duitku Python SDK", long_description=long_description, url="https://github.com/idoyudha/duitku-python",