Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions examples/fastapi/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MERCHANT_CODE=EXAMPLE_MERCHANT_CODE
API_KEY=EXAMPLE_API_KEY
90 changes: 90 additions & 0 deletions examples/fastapi/main.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions examples/fastapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
duitku==0.2.9
fastapi==0.115.12
pydantic==2.11.4
python-dotenv==1.1.0
34 changes: 34 additions & 0 deletions examples/invoice.md
Original file line number Diff line number Diff line change
@@ -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)
```
30 changes: 30 additions & 0 deletions examples/payment.md
Original file line number Diff line number Diff line change
@@ -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)
```
61 changes: 61 additions & 0 deletions examples/transaction.md
Original file line number Diff line number Diff line change
@@ -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)
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "Duitku"
version = "0.2.9"
version = "0.2.10"
authors = [
{name = "Ido Yudhatama", email = "idowidya.yudhatama@gmail.com"},
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down