@rangka-os/create 0.5.0-alpha.27 → 0.5.0-alpha.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/base/apps/absen_karyawan/app.rk +37 -0
- package/template/base/apps/absen_karyawan/dashboards/absen_hari_ini.rk +20 -0
- package/template/base/apps/absen_karyawan/dashboards/absen_karyawan_saya.rk +14 -0
- package/template/base/apps/absen_karyawan/dashboards/rekap_absen_karyawan.rk +12 -0
- package/template/base/apps/jasa_proyek/app.rk +4 -1
- package/template/base/apps/kasir/app.rk +5 -1
- package/template/base/apps/kasir/dashboards/kasir_ringkas.rk +4 -0
- package/template/base/apps/kasir/skills/rangka-app-kasir/SKILL.md +20 -0
- package/template/base/apps/pembukuan/app.rk +3 -0
- package/template/base/connectors/midtrans/connector.rk +249 -0
- package/template/base/connectors/midtrans/fixtures/charge_gopay.json +34 -0
- package/template/base/connectors/midtrans/fixtures/charge_qris.json +23 -0
- package/template/base/connectors/midtrans/fixtures/charge_va.json +20 -0
- package/template/base/connectors/midtrans/fixtures/create_snap.json +4 -0
- package/template/base/connectors/midtrans/fixtures/expect.json +88 -0
- package/template/base/connectors/midtrans/fixtures/get_status.json +15 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified.json +28 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_challenge.json +24 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_expire.json +24 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_other_amount.json +28 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_partial_refund.json +34 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_pending.json +31 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_refund.json +34 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_relabelled.json +28 -0
- package/template/base/connectors/midtrans/fixtures/payment_notified_va.json +32 -0
- package/template/base/connectors/midtrans/fixtures/signature_vector.txt +3 -0
- package/template/base/connectors/midtrans/mock/midtrans_mock.py +335 -0
- package/template/base/connectors/rangka_whatsapp/README.md +105 -0
- package/template/base/connectors/rangka_whatsapp/connector.rk +141 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/expect.json +9 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/message_received.json +1 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/message_status.json +1 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/message_status_refused.json +1 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/opted_out.json +1 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/send_template.json +1 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/send_template_duplicate.json +1 -0
- package/template/base/connectors/rangka_whatsapp/fixtures/set_opt_out.json +1 -0
- package/template/base/connectors/rangka_whatsapp/mock/rangka_whatsapp_mock.py +354 -0
- package/template/base/connectors/shopee/connector.rk +360 -0
- package/template/base/connectors/shopee/fixtures/expect.json +119 -0
- package/template/base/connectors/shopee/fixtures/get_models.json +52 -0
- package/template/base/connectors/shopee/fixtures/get_order_detail.json +396 -0
- package/template/base/connectors/shopee/fixtures/get_settlement.json +90 -0
- package/template/base/connectors/shopee/fixtures/get_tracking.json +13 -0
- package/template/base/connectors/shopee/fixtures/list_items.json +29 -0
- package/template/base/connectors/shopee/fixtures/list_orders.json +31 -0
- package/template/base/connectors/shopee/fixtures/list_settlements.json +15 -0
- package/template/base/connectors/shopee/fixtures/order_changed.json +101 -0
- package/template/base/connectors/shopee/fixtures/order_changed_cancelled.json +72 -0
- package/template/base/connectors/shopee/fixtures/order_changed_completed.json +101 -0
- package/template/base/connectors/shopee/fixtures/order_changed_in_cancel.json +72 -0
- package/template/base/connectors/shopee/fixtures/order_changed_unpaid.json +71 -0
- package/template/base/connectors/shopee/fixtures/order_settled.json +92 -0
- package/template/base/connectors/shopee/fixtures/push_received.json +12 -0
- package/template/base/connectors/shopee/fixtures/push_received_tracking.json +11 -0
- package/template/base/connectors/shopee/fixtures/update_stock.json +15 -0
- package/template/base/connectors/shopee/mock/shopee_mock.py +894 -0
- package/template/base/connectors/tiktok_shop/connector.rk +300 -0
- package/template/base/connectors/tiktok_shop/fixtures/expect.json +105 -0
- package/template/base/connectors/tiktok_shop/fixtures/get_order_detail.json +136 -0
- package/template/base/connectors/tiktok_shop/fixtures/get_settlement.json +83 -0
- package/template/base/connectors/tiktok_shop/fixtures/get_tracking.json +28 -0
- package/template/base/connectors/tiktok_shop/fixtures/list_orders.json +242 -0
- package/template/base/connectors/tiktok_shop/fixtures/list_products.json +77 -0
- package/template/base/connectors/tiktok_shop/fixtures/list_settlements.json +22 -0
- package/template/base/connectors/tiktok_shop/fixtures/list_shops.json +17 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_changed.json +129 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_changed_cancelled.json +81 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_changed_completed.json +106 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_changed_on_hold.json +104 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_changed_tokopedia.json +106 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_changed_unpaid.json +79 -0
- package/template/base/connectors/tiktok_shop/fixtures/order_settled.json +73 -0
- package/template/base/connectors/tiktok_shop/fixtures/update_stock.json +6 -0
- package/template/base/connectors/tiktok_shop/fixtures/webhook_received.json +12 -0
- package/template/base/connectors/tiktok_shop/fixtures/webhook_received_cancellation.json +13 -0
- package/template/base/connectors/tiktok_shop/mock/tiktok_shop_mock.py +819 -0
- package/template/base/connectors/whatsapp_business/connector.rk +3 -1
- package/template/base/connectors/whatsapp_business/templates.md +13 -1
- package/template/base/modules/accounting/flows/gl_asset_disposal_post.rk +68 -0
- package/template/base/modules/accounting/flows/gl_asset_disposal_reverse.rk +194 -0
- package/template/base/modules/accounting/flows/gl_depreciation_run_post.rk +43 -0
- package/template/base/modules/accounting/flows/gl_depreciation_run_reverse.rk +36 -0
- package/template/base/modules/accounting/flows/gl_fixed_asset_post.rk +51 -0
- package/template/base/modules/accounting/flows/gl_fixed_asset_reverse.rk +194 -0
- package/template/base/modules/accounting/flows/gl_vendor_bill_post.rk +2 -2
- package/template/base/modules/accounting/models/gl_entry.rk +2 -0
- package/template/base/modules/accounting/module.rk +2 -2
- package/template/base/modules/attendance/flows/attendance_missing_digest.rk +30 -0
- package/template/base/modules/attendance/flows/attendance_period_on_cancel.rk +15 -0
- package/template/base/modules/attendance/flows/attendance_period_on_submit.rk +60 -0
- package/template/base/modules/attendance/flows/staff_attendance_cancel_guard.rk +14 -0
- package/template/base/modules/attendance/flows/staff_attendance_guard_created.rk +16 -0
- package/template/base/modules/attendance/flows/staff_attendance_guard_submitted.rk +37 -0
- package/template/base/modules/attendance/flows/staff_attendance_guard_updated.rk +14 -0
- package/template/base/modules/attendance/models/attendance_period.rk +62 -0
- package/template/base/modules/attendance/models/attendance_summary.rk +37 -0
- package/template/base/modules/attendance/models/staff_attendance.rk +281 -0
- package/template/base/modules/attendance/models/staff_attendance_guard.rk +50 -0
- package/template/base/modules/attendance/module.rk +18 -0
- package/template/base/modules/attendance/screens/absen_outlet.rk +22 -0
- package/template/base/modules/catalogue/models/item.rk +69 -0
- package/template/base/modules/catalogue/module.rk +1 -1
- package/template/base/modules/contacts/models/customer.rk +43 -19
- package/template/base/modules/contacts/module.rk +1 -1
- package/template/base/modules/coretax/module.rk +1 -1
- package/template/base/modules/coretax/print/coretax_faktur.rk +3 -2
- package/template/base/modules/coretax/print/coretax_faktur.xml +3 -1
- package/template/base/modules/coretax/print/rekap_ppn.html +9 -7
- package/template/base/modules/courses/flows/charge_invoice_on_submit.rk +15 -0
- package/template/base/modules/courses/module.rk +1 -1
- package/template/base/modules/courses/screens/absen_kelas.rk +1 -0
- package/template/base/modules/fixed_assets/flows/asset_disposal_on_cancel.rk +14 -0
- package/template/base/modules/fixed_assets/flows/asset_disposal_on_submit.rk +21 -0
- package/template/base/modules/fixed_assets/flows/asset_from_vendor_bill.rk +41 -0
- package/template/base/modules/fixed_assets/flows/depreciation_run_fill.rk +28 -0
- package/template/base/modules/fixed_assets/flows/depreciation_run_monthly.rk +36 -0
- package/template/base/modules/fixed_assets/flows/depreciation_run_on_cancel.rk +30 -0
- package/template/base/modules/fixed_assets/flows/depreciation_run_on_submit.rk +34 -0
- package/template/base/modules/fixed_assets/flows/fixed_asset_on_cancel.rk +24 -0
- package/template/base/modules/fixed_assets/flows/fixed_asset_on_submit.rk +69 -0
- package/template/base/modules/fixed_assets/flows/fixed_assets_setup.rk +29 -0
- package/template/base/modules/fixed_assets/flows/opening_balance_asset_guard.rk +15 -0
- package/template/base/modules/fixed_assets/flows/vendor_bill_asset_guard.rk +14 -0
- package/template/base/modules/fixed_assets/imports/asset_list.rk +22 -0
- package/template/base/modules/fixed_assets/models/asset_bill_line.rk +24 -0
- package/template/base/modules/fixed_assets/models/asset_book.rk +83 -0
- package/template/base/modules/fixed_assets/models/asset_category.rk +54 -0
- package/template/base/modules/fixed_assets/models/asset_disposal.rk +97 -0
- package/template/base/modules/fixed_assets/models/asset_guard.rk +90 -0
- package/template/base/modules/fixed_assets/models/depreciation_line.rk +13 -0
- package/template/base/modules/fixed_assets/models/depreciation_run.rk +65 -0
- package/template/base/modules/fixed_assets/models/fixed_asset.rk +165 -0
- package/template/base/modules/fixed_assets/models/fixed_asset_setting.rk +34 -0
- package/template/base/modules/fixed_assets/module.rk +30 -0
- package/template/base/modules/fixed_assets/print/fixed_asset_register.html +45 -0
- package/template/base/modules/fixed_assets/print/fixed_asset_register.rk +17 -0
- package/template/base/modules/invoicing/flows/invoice_due_digest.rk +45 -7
- package/template/base/modules/invoicing/models/sales_invoice_item.rk +4 -1
- package/template/base/modules/invoicing/module.rk +15 -2
- package/template/base/modules/kitchen/screens/dapur.rk +1 -0
- package/template/base/modules/outlets/models/outlet.rk +69 -0
- package/template/base/modules/outlets/module.rk +1 -1
- package/template/base/modules/payments/flows/payment_from_midtrans.rk +85 -0
- package/template/base/modules/payments/flows/payment_refund_from_midtrans.rk +22 -0
- package/template/base/modules/payments/models/payment.rk +2 -1
- package/template/base/modules/payments/module.rk +1 -1
- package/template/base/modules/payroll/flows/payroll_close_on_cancel.rk +8 -5
- package/template/base/modules/payroll/flows/payroll_close_on_submit.rk +8 -5
- package/template/base/modules/payroll/flows/payroll_reminder.rk +106 -0
- package/template/base/modules/payroll/flows/payroll_run_overlap_guard_created.rk +5 -3
- package/template/base/modules/payroll/flows/payroll_run_overlap_guard_updated.rk +5 -3
- package/template/base/modules/payroll/flows/payslip_from_recap.rk +1 -1
- package/template/base/modules/payroll/imports/payroll_profile_list.rk +27 -0
- package/template/base/modules/payroll/models/payroll_close.rk +10 -6
- package/template/base/modules/payroll/models/payroll_run.rk +64 -15
- package/template/base/modules/payroll/models/payslip.rk +48 -9
- package/template/base/modules/payroll/module.rk +22 -5
- package/template/base/modules/payroll/print/payslip.html +4 -1
- package/template/base/modules/pos/models/pos_sale.rk +136 -9
- package/template/base/modules/pos/models/pos_sale_item.rk +33 -1
- package/template/base/modules/pos/module.rk +5 -3
- package/template/base/modules/pos/print/pos_receipt.html +7 -3
- package/template/base/modules/pos/screens/kasir.rk +7 -2
- package/template/base/modules/procurement/flows/reorder_draft_po.rk +57 -0
- package/template/base/modules/procurement/models/vendor_bill.rk +21 -2
- package/template/base/modules/procurement/module.rk +11 -2
- package/template/base/modules/projects/screens/absen.rk +1 -0
- package/template/base/modules/promotions/flows/promo_code_batch_on_submit.rk +26 -0
- package/template/base/modules/promotions/flows/promotion_apply.rk +110 -0
- package/template/base/modules/promotions/flows/promotion_apply_on_create.rk +110 -0
- package/template/base/modules/promotions/flows/promotion_apply_on_delete.rk +111 -0
- package/template/base/modules/promotions/flows/promotion_apply_on_update.rk +110 -0
- package/template/base/modules/promotions/flows/promotion_on_sale.rk +95 -0
- package/template/base/modules/promotions/flows/promotion_on_sale_cancel.rk +43 -0
- package/template/base/modules/promotions/models/promo_code.rk +27 -0
- package/template/base/modules/promotions/models/promo_code_batch.rk +36 -0
- package/template/base/modules/promotions/models/promo_guard.rk +44 -0
- package/template/base/modules/promotions/models/promotion.rk +197 -0
- package/template/base/modules/promotions/models/promotion_ledger.rk +35 -0
- package/template/base/modules/promotions/module.rk +20 -0
- package/template/base/modules/rental/models/rental_unit.rk +13 -3
- package/template/base/modules/rental/module.rk +2 -2
- package/template/base/modules/rental/screens/alat_keluar.rk +1 -0
- package/template/base/modules/rental/screens/alat_kembali.rk +1 -0
- package/template/base/modules/rental/screens/jadwal_alat.rk +1 -0
- package/template/base/modules/stock/flows/stock_low_alert.rk +65 -0
- package/template/base/modules/stock/flows/stock_negative_alert.rk +14 -5
- package/template/base/modules/stock/models/stock_reorder.rk +34 -0
- package/template/base/modules/stock/module.rk +17 -2
- package/template/base/modules/subscriptions/screens/catat_tagih.rk +1 -0
- package/template/base/modules/subscriptions/screens/rute_tagih.rk +1 -0
- package/template/base/modules/users/flows/summary_daily.rk +83 -0
- package/template/base/modules/users/flows/summary_monthly.rk +83 -0
- package/template/base/modules/users/flows/summary_weekly.rk +83 -0
- package/template/base/modules/users/models/business_summary.rk +67 -0
- package/template/base/modules/users/models/summary_setting.rk +35 -0
- package/template/base/modules/users/models/user.rk +11 -3
- package/template/base/modules/users/module.rk +21 -2
- package/template/base/modules/users/roles/employee.rk +8 -0
- package/template/base/modules/users/roles/outlet_supervisor.rk +7 -0
- package/template/base/modules/whatsapp/flows/whatsapp_customer_opt_out.rk +16 -0
- package/template/base/modules/whatsapp/flows/whatsapp_customer_opt_out_new.rk +17 -0
- package/template/base/modules/whatsapp/flows/whatsapp_message_status.rk +24 -0
- package/template/base/modules/whatsapp/flows/whatsapp_opted_out.rk +26 -0
- package/template/base/modules/whatsapp/models/whatsapp_message.rk +99 -0
- package/template/base/modules/whatsapp/models/whatsapp_opt_out.rk +44 -0
- package/template/base/modules/whatsapp/module.rk +23 -0
- package/template/base/modules/whatsapp_booking/flows/whatsapp_booking_tomorrow.rk +48 -0
- package/template/base/modules/whatsapp_booking/module.rk +13 -0
- package/template/base/modules/whatsapp_order_ready/flows/whatsapp_pickup_on_sale.rk +19 -0
- package/template/base/modules/whatsapp_order_ready/flows/whatsapp_ticket_ready.rk +40 -0
- package/template/base/modules/whatsapp_order_ready/models/whatsapp_pickup.rk +22 -0
- package/template/base/modules/whatsapp_order_ready/module.rk +14 -0
- package/template/base/modules/whatsapp_receipt/flows/whatsapp_receipt_on_sale.rk +43 -0
- package/template/base/modules/whatsapp_receipt/module.rk +13 -0
- package/template/base/modules/whatsapp_reminder/flows/whatsapp_invoice_overdue.rk +64 -0
- package/template/base/modules/whatsapp_reminder/module.rk +15 -0
- package/template/base/modules/workforce/imports/worker_list.rk +4 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "settlement",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "qris",
|
|
9
|
+
"order_id": "INV-2026-00007",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "750000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"transaction_type": "on-us",
|
|
15
|
+
"settlement_time": "2026-11-19 10:13:05",
|
|
16
|
+
"issuer": "gopay",
|
|
17
|
+
"acquirer": "gopay",
|
|
18
|
+
"confirmed": {
|
|
19
|
+
"gateway_ref": "INV-2026-00007",
|
|
20
|
+
"status": "settlement",
|
|
21
|
+
"status_code": "200",
|
|
22
|
+
"paid": true,
|
|
23
|
+
"paid_amount": "750000.00",
|
|
24
|
+
"channel": "qris",
|
|
25
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
26
|
+
"refund_amount": null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "capture",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "credit_card",
|
|
9
|
+
"order_id": "INV-2026-00010",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "990000.00",
|
|
12
|
+
"fraud_status": "challenge",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"confirmed": {
|
|
15
|
+
"gateway_ref": "INV-2026-00010",
|
|
16
|
+
"status": "capture",
|
|
17
|
+
"status_code": "200",
|
|
18
|
+
"paid": false,
|
|
19
|
+
"paid_amount": "990000.00",
|
|
20
|
+
"channel": "credit_card",
|
|
21
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
22
|
+
"refund_amount": null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "expire",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "407",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "qris",
|
|
9
|
+
"order_id": "INV-2026-00009",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "120000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"confirmed": {
|
|
15
|
+
"gateway_ref": "INV-2026-00009",
|
|
16
|
+
"status": "expire",
|
|
17
|
+
"status_code": "407",
|
|
18
|
+
"paid": false,
|
|
19
|
+
"paid_amount": "120000.00",
|
|
20
|
+
"channel": "qris",
|
|
21
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
22
|
+
"refund_amount": null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "settlement",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "qris",
|
|
9
|
+
"order_id": "INV-2026-00013",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "750000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"transaction_type": "on-us",
|
|
15
|
+
"settlement_time": "2026-11-19 10:13:05",
|
|
16
|
+
"issuer": "gopay",
|
|
17
|
+
"acquirer": "gopay",
|
|
18
|
+
"confirmed": {
|
|
19
|
+
"gateway_ref": "INV-2026-00013",
|
|
20
|
+
"status": "settlement",
|
|
21
|
+
"status_code": "200",
|
|
22
|
+
"paid": true,
|
|
23
|
+
"paid_amount": "7500.00",
|
|
24
|
+
"channel": "qris",
|
|
25
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
26
|
+
"refund_amount": null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "partial_refund",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "gopay",
|
|
9
|
+
"order_id": "INV-2026-00007",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "750000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"refund_amount": "250000.00",
|
|
15
|
+
"refunds": [
|
|
16
|
+
{
|
|
17
|
+
"refund_chargeback_id": 2,
|
|
18
|
+
"refund_amount": "250000.00",
|
|
19
|
+
"created_at": "2026-11-20 09:00:00",
|
|
20
|
+
"reason": "barang kurang",
|
|
21
|
+
"refund_key": "retur-2"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"confirmed": {
|
|
25
|
+
"gateway_ref": "INV-2026-00007",
|
|
26
|
+
"status": "partial_refund",
|
|
27
|
+
"status_code": "200",
|
|
28
|
+
"paid": false,
|
|
29
|
+
"paid_amount": "750000.00",
|
|
30
|
+
"channel": "gopay",
|
|
31
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
32
|
+
"refund_amount": "250000.00"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "pending",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "201",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "bank_transfer",
|
|
9
|
+
"order_id": "INV-2026-00008",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "400000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"va_numbers": [
|
|
15
|
+
{
|
|
16
|
+
"va_number": "812785002530231",
|
|
17
|
+
"bank": "bca"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"payment_amounts": [],
|
|
21
|
+
"confirmed": {
|
|
22
|
+
"gateway_ref": "INV-2026-00008",
|
|
23
|
+
"status": "pending",
|
|
24
|
+
"status_code": "201",
|
|
25
|
+
"paid": false,
|
|
26
|
+
"paid_amount": "400000.00",
|
|
27
|
+
"channel": "bank_transfer",
|
|
28
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
29
|
+
"refund_amount": null
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "refund",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "qris",
|
|
9
|
+
"order_id": "INV-2026-00007",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "750000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"refund_amount": "750000.00",
|
|
15
|
+
"refunds": [
|
|
16
|
+
{
|
|
17
|
+
"refund_chargeback_id": 1,
|
|
18
|
+
"refund_amount": "750000.00",
|
|
19
|
+
"created_at": "2026-11-20 09:00:00",
|
|
20
|
+
"reason": "salah tagih",
|
|
21
|
+
"refund_key": "retur-1"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"confirmed": {
|
|
25
|
+
"gateway_ref": "INV-2026-00007",
|
|
26
|
+
"status": "refund",
|
|
27
|
+
"status_code": "200",
|
|
28
|
+
"paid": false,
|
|
29
|
+
"paid_amount": "750000.00",
|
|
30
|
+
"channel": "qris",
|
|
31
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
32
|
+
"refund_amount": "750000.00"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "settlement",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000007",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "qris",
|
|
9
|
+
"order_id": "INV-2026-00012",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "750000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"transaction_type": "on-us",
|
|
15
|
+
"settlement_time": "2026-11-19 10:13:05",
|
|
16
|
+
"issuer": "gopay",
|
|
17
|
+
"acquirer": "gopay",
|
|
18
|
+
"confirmed": {
|
|
19
|
+
"gateway_ref": "INV-2026-00012",
|
|
20
|
+
"status": "cancel",
|
|
21
|
+
"status_code": "200",
|
|
22
|
+
"paid": false,
|
|
23
|
+
"paid_amount": "750000.00",
|
|
24
|
+
"channel": "qris",
|
|
25
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000012",
|
|
26
|
+
"refund_amount": null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"transaction_time": "2026-11-19 10:12:40",
|
|
3
|
+
"transaction_status": "settlement",
|
|
4
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000008",
|
|
5
|
+
"status_message": "midtrans payment notification",
|
|
6
|
+
"status_code": "200",
|
|
7
|
+
"signature_key": "(hex SHA-512, see signature_vector.txt)",
|
|
8
|
+
"payment_type": "bank_transfer",
|
|
9
|
+
"order_id": "INV-2026-00008~2",
|
|
10
|
+
"merchant_id": "G000000001",
|
|
11
|
+
"gross_amount": "400000.00",
|
|
12
|
+
"fraud_status": "accept",
|
|
13
|
+
"currency": "IDR",
|
|
14
|
+
"settlement_time": "2026-11-19 11:02:11",
|
|
15
|
+
"va_numbers": [
|
|
16
|
+
{
|
|
17
|
+
"va_number": "812785002530231",
|
|
18
|
+
"bank": "bca"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"payment_amounts": [],
|
|
22
|
+
"confirmed": {
|
|
23
|
+
"gateway_ref": "INV-2026-00008~2",
|
|
24
|
+
"status": "settlement",
|
|
25
|
+
"status_code": "200",
|
|
26
|
+
"paid": true,
|
|
27
|
+
"paid_amount": "400000.00",
|
|
28
|
+
"channel": "bank_transfer",
|
|
29
|
+
"transaction_id": "9f1c7a52-3b8e-4d61-a2f4-000000000008",
|
|
30
|
+
"refund_amount": null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
4c2b157a97326e6e42210b9583b0325e80af105c63a7c29634ea9208c829ee2c294c4606d7ca7b3063752886108f162fb18dc2bcb83e758b9ef4319a2ce1a33d
|
|
2
|
+
# hex(SHA-512('INV-2026-00001' + '200' + '750000.00' + 'SB-Mid-server-dummy-test-0001')), the vector rangka-os
|
|
3
|
+
# kernel/internal/server/connectors_bodysig_test.go and tests/check_midtrans_mock.py both check
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""A local stand-in for the Midtrans sandbox (Snap, Core API charge, status), for demos and tests without an account.
|
|
3
|
+
|
|
4
|
+
MIDTRANS_MOCK_SERVER_KEY=SB-Mid-server-dummy-demo python3 midtrans/mock/midtrans_mock.py --port 8903 \
|
|
5
|
+
--notify-url http://127.0.0.1:8080/hooks/<org>/midtrans/payment_notified
|
|
6
|
+
|
|
7
|
+
Dummy keys only. The mock signs any notification it is asked for (/simulate/*), without authentication: it is a
|
|
8
|
+
signing oracle for its key. So it listens on 127.0.0.1 only, reads the key from MIDTRANS_MOCK_SERVER_KEY (not argv,
|
|
9
|
+
which `ps` shows), and refuses a key that does not say it is a dummy (a part "dummy" or "test" between - _ or .).
|
|
10
|
+
Never give it a server key from the Midtrans dashboard, sandbox or production.
|
|
11
|
+
|
|
12
|
+
Stdlib only. What it does, in Midtrans's formats (rangka connector midtrans, research in Juragan's
|
|
13
|
+
reports/keputusan-riset/midtrans-connector.md):
|
|
14
|
+
|
|
15
|
+
- POST /snap/v1/transactions Basic auth (server key as the user name, empty password); answers 201 with token and
|
|
16
|
+
redirect_url. An order id that was used before is 400, as at Midtrans (one transaction per order id).
|
|
17
|
+
- GET /snap/v3/redirection/<token> a small page standing in for the Snap payment page (a pay button).
|
|
18
|
+
- POST /v2/charge payment_type qris, bank_transfer (bca, bni, bri, cimb answer va_numbers; permata answers
|
|
19
|
+
permata_va_number) or gopay: status_code 201, transaction_status pending, actions / qr_string / expiry_time.
|
|
20
|
+
- GET /v2/<order_id>/status the transaction as Midtrans reports it (with signature_key); 404 when unknown.
|
|
21
|
+
- POST /simulate/pay/<order_id>[?payment_type=qris][&status=deny|expire|cancel] marks the payment and sends the
|
|
22
|
+
notification to --notify-url, the way the sandbox simulator does; answers with the notification's HTTP status.
|
|
23
|
+
- POST /simulate/refund/<order_id>[?amount=N] a settled payment refunded (all, or N: partial_refund): a notification
|
|
24
|
+
of transaction_status refund or partial_refund, status_code 200. Not money in.
|
|
25
|
+
- POST /simulate/resend/<order_id> the last notification of that order once more (Midtrans retries).
|
|
26
|
+
- POST /simulate/notify body {"order_id", "gross_amount", "transaction_status", "payment_type"}: a notification for
|
|
27
|
+
an order the mock never saw (a payment made outside Snap and the Core API).
|
|
28
|
+
- GET /calls every request it received (for tests).
|
|
29
|
+
|
|
30
|
+
A notification's signature_key is hex(SHA-512(order_id + status_code + gross_amount + server key)): sign() below is
|
|
31
|
+
the reference the kernel's body-field verification is checked against (rangka-os contract 0002, 19 Nov 2026).
|
|
32
|
+
The kernel only sends requests that carry a secret over https to the hosts the connector declares (rangka-os contract
|
|
33
|
+
0017 §5), so a local kernel never calls this mock: the mock is the payer's side, and its API endpoints are what a
|
|
34
|
+
test calls with the requests the connector describes.
|
|
35
|
+
"""
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
import argparse
|
|
39
|
+
import base64
|
|
40
|
+
import hashlib
|
|
41
|
+
import hmac
|
|
42
|
+
import html
|
|
43
|
+
import json
|
|
44
|
+
import os
|
|
45
|
+
import re
|
|
46
|
+
import sys
|
|
47
|
+
import threading
|
|
48
|
+
import urllib.error
|
|
49
|
+
import urllib.parse
|
|
50
|
+
import urllib.request
|
|
51
|
+
import uuid
|
|
52
|
+
from datetime import datetime, timedelta, timezone
|
|
53
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
54
|
+
|
|
55
|
+
WIB = timezone(timedelta(hours=7))
|
|
56
|
+
ORDER_ID = re.compile(r"^[A-Za-z0-9._~-]{1,50}$") # Midtrans: letters, digits, dash, underscore, tilde and dot
|
|
57
|
+
# status_code per transaction_status, as Midtrans sends it: 200 success, 201 pending, 202 denied, 407 expired
|
|
58
|
+
STATUS_CODE = {"settlement": "200", "capture": "200", "refund": "200", "partial_refund": "200", "cancel": "200",
|
|
59
|
+
"pending": "201", "deny": "202", "expire": "407"}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def sign(order_id: str, status_code: str, gross_amount: str, server_key: str) -> str:
|
|
63
|
+
"""Midtrans signature_key: hex(SHA-512(order_id + status_code + gross_amount + server key)), no separators."""
|
|
64
|
+
return hashlib.sha512((order_id + status_code + gross_amount + server_key).encode()).hexdigest()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def now_wib() -> str:
|
|
68
|
+
return datetime.now(WIB).strftime("%Y-%m-%d %H:%M:%S")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def money(amount: int) -> str:
|
|
72
|
+
return f"{int(amount)}.00"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class State:
|
|
76
|
+
"""The mock's memory. server_key is a dummy key: whoever reaches the mock can have anything signed with it."""
|
|
77
|
+
|
|
78
|
+
def __init__(self, server_key, notify_url, merchant_id="G000000001"):
|
|
79
|
+
self.server_key, self.notify_url, self.merchant_id = server_key, notify_url, merchant_id
|
|
80
|
+
self.orders = {} # order_id -> {transaction_id, gross_amount, payment_type, status, refunded, extra, last}
|
|
81
|
+
self.tokens = {} # snap token -> order_id
|
|
82
|
+
self.calls = []
|
|
83
|
+
self.lock = threading.Lock()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def body_of(state: State, order_id: str, o: dict, status: str, **more) -> dict:
|
|
87
|
+
"""A notification (and status answer) for an order, signed."""
|
|
88
|
+
code = STATUS_CODE.get(status, "200")
|
|
89
|
+
gross = money(o["gross_amount"])
|
|
90
|
+
d = {"transaction_time": o["time"], "transaction_status": status, "transaction_id": o["transaction_id"],
|
|
91
|
+
"status_message": "midtrans payment notification", "status_code": code,
|
|
92
|
+
"signature_key": sign(order_id, code, gross, state.server_key), "payment_type": o["payment_type"],
|
|
93
|
+
"order_id": order_id, "merchant_id": state.merchant_id, "gross_amount": gross, "fraud_status": "accept",
|
|
94
|
+
"currency": "IDR"}
|
|
95
|
+
if status in ("settlement", "refund", "partial_refund"):
|
|
96
|
+
d["settlement_time"] = o.get("settled") or now_wib()
|
|
97
|
+
d.update(o.get("extra") or {})
|
|
98
|
+
d.update(more)
|
|
99
|
+
return d
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def post(url: str, body: dict) -> int:
|
|
103
|
+
"""Send one notification as Midtrans does; returns the HTTP status (0 when unreachable)."""
|
|
104
|
+
req = urllib.request.Request(url, data=json.dumps(body, separators=(",", ":")).encode(), method="POST",
|
|
105
|
+
headers={"Content-Type": "application/json", "User-Agent": "Veritrans (mock)"})
|
|
106
|
+
try:
|
|
107
|
+
with urllib.request.urlopen(req, timeout=10) as r:
|
|
108
|
+
return r.status
|
|
109
|
+
except urllib.error.HTTPError as e:
|
|
110
|
+
return e.code
|
|
111
|
+
except OSError:
|
|
112
|
+
return 0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def notify(state: State, order_id: str, o: dict, status: str, **more) -> int:
|
|
116
|
+
body = body_of(state, order_id, o, status, **more)
|
|
117
|
+
o["last"] = body
|
|
118
|
+
return post(state.notify_url, body)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def handler(state: State):
|
|
122
|
+
class H(BaseHTTPRequestHandler):
|
|
123
|
+
def log_message(self, *a):
|
|
124
|
+
pass
|
|
125
|
+
|
|
126
|
+
def send(self, code, obj, ctype="application/json"):
|
|
127
|
+
raw = obj.encode() if isinstance(obj, str) else json.dumps(obj).encode()
|
|
128
|
+
self.send_response(code)
|
|
129
|
+
self.send_header("Content-Type", ctype)
|
|
130
|
+
self.send_header("Content-Length", str(len(raw)))
|
|
131
|
+
self.end_headers()
|
|
132
|
+
self.wfile.write(raw)
|
|
133
|
+
|
|
134
|
+
def body(self) -> bytes:
|
|
135
|
+
n = int(self.headers.get("Content-Length") or 0)
|
|
136
|
+
return self.rfile.read(n) if n else b""
|
|
137
|
+
|
|
138
|
+
def authorized(self) -> bool:
|
|
139
|
+
want = "Basic " + base64.b64encode((state.server_key + ":").encode()).decode()
|
|
140
|
+
return hmac.compare_digest(self.headers.get("Authorization", ""), want)
|
|
141
|
+
|
|
142
|
+
def refuse(self):
|
|
143
|
+
self.send(401, {"status_code": "401", "status_message": "Transaction cannot be authorized with the current client/server key.",
|
|
144
|
+
"id": str(uuid.uuid4())})
|
|
145
|
+
|
|
146
|
+
def host(self) -> str:
|
|
147
|
+
return self.headers.get("Host", "127.0.0.1")
|
|
148
|
+
|
|
149
|
+
def do_GET(self):
|
|
150
|
+
path = urllib.parse.urlparse(self.path).path
|
|
151
|
+
if path == "/calls":
|
|
152
|
+
with state.lock:
|
|
153
|
+
return self.send(200, state.calls)
|
|
154
|
+
if path.startswith("/snap/v3/redirection/"):
|
|
155
|
+
order_id = state.tokens.get(path.rsplit("/", 1)[-1])
|
|
156
|
+
o = state.orders.get(order_id)
|
|
157
|
+
if not o:
|
|
158
|
+
return self.send(404, {"error_messages": ["token not found"]})
|
|
159
|
+
return self.send(200, f"<!doctype html><meta charset=utf-8><title>Midtrans Snap (mock)</title>"
|
|
160
|
+
f"<h1>Bayar {html.escape(order_id)}</h1><p>Rp {o['gross_amount']:,}</p>"
|
|
161
|
+
f"<form method=post action=/simulate/pay/{urllib.parse.quote(order_id, safe='')}><button>Simulasi bayar QRIS</button></form>",
|
|
162
|
+
"text/html; charset=utf-8")
|
|
163
|
+
m = re.match(r"^/v2/(qris|gopay)/([^/]+)/qr-code$", path)
|
|
164
|
+
if m:
|
|
165
|
+
for o in state.orders.values():
|
|
166
|
+
if o["transaction_id"] == m.group(2):
|
|
167
|
+
return self.send(200, o.get("qr_string", ""), "text/plain; charset=utf-8")
|
|
168
|
+
return self.send(404, {"status_code": "404", "status_message": "Transaction doesn't exist.", "id": str(uuid.uuid4())})
|
|
169
|
+
m = re.match(r"^/v2/([^/]+)/status$", path)
|
|
170
|
+
if m:
|
|
171
|
+
if not self.authorized():
|
|
172
|
+
return self.refuse()
|
|
173
|
+
order_id = urllib.parse.unquote(m.group(1))
|
|
174
|
+
o = state.orders.get(order_id)
|
|
175
|
+
if not o or not o.get("status"):
|
|
176
|
+
return self.send(404, {"status_code": "404", "status_message": "Transaction doesn't exist.", "id": str(uuid.uuid4())})
|
|
177
|
+
more = {"status_message": "Success, transaction is found"}
|
|
178
|
+
if o.get("refunded"):
|
|
179
|
+
more["refund_amount"] = money(o["refunded"])
|
|
180
|
+
return self.send(200, body_of(state, order_id, o, o["status"], **more))
|
|
181
|
+
self.send(404, {"status_code": "404", "status_message": "The requested resource is not found"})
|
|
182
|
+
|
|
183
|
+
def new_order(self, order_id, amount, payment_type, status, **extra):
|
|
184
|
+
"""One transaction per order id; None when the id was used before."""
|
|
185
|
+
with state.lock:
|
|
186
|
+
if order_id in state.orders:
|
|
187
|
+
return None
|
|
188
|
+
o = {"transaction_id": str(uuid.uuid4()), "gross_amount": amount, "payment_type": payment_type,
|
|
189
|
+
"status": status, "refunded": 0, "time": now_wib(), "extra": extra}
|
|
190
|
+
state.orders[order_id] = o
|
|
191
|
+
return o
|
|
192
|
+
|
|
193
|
+
def do_POST(self):
|
|
194
|
+
u = urllib.parse.urlparse(self.path)
|
|
195
|
+
q = urllib.parse.parse_qs(u.query)
|
|
196
|
+
raw = self.body()
|
|
197
|
+
with state.lock:
|
|
198
|
+
state.calls.append({"method": "POST", "path": u.path, "headers": {k: v for k, v in self.headers.items() if k.lower() != "authorization"},
|
|
199
|
+
"body": raw.decode(errors="replace")})
|
|
200
|
+
if u.path in ("/snap/v1/transactions", "/v2/charge"):
|
|
201
|
+
if not self.authorized():
|
|
202
|
+
return self.refuse()
|
|
203
|
+
try:
|
|
204
|
+
req = json.loads(raw)
|
|
205
|
+
td = req["transaction_details"]
|
|
206
|
+
order_id, amount = str(td["order_id"]), int(float(td["gross_amount"]))
|
|
207
|
+
except (ValueError, KeyError, TypeError):
|
|
208
|
+
return self.send(400, {"status_code": "400", "status_message": "One or more parameters in the payload is invalid.",
|
|
209
|
+
"error_messages": ["transaction_details.order_id is required"]})
|
|
210
|
+
if not ORDER_ID.match(order_id) or amount <= 0:
|
|
211
|
+
return self.send(400, {"status_code": "400", "status_message": "One or more parameters in the payload is invalid.",
|
|
212
|
+
"error_messages": ["transaction_details.order_id format is invalid" if amount > 0 else "transaction_details.gross_amount is not equal to the sum of item_details"]})
|
|
213
|
+
if u.path == "/snap/v1/transactions":
|
|
214
|
+
# no payment method yet: the payer picks one on the page (the mock's button pays by QRIS)
|
|
215
|
+
if self.new_order(order_id, amount, "qris", "") is None:
|
|
216
|
+
return self.send(400, {"error_messages": ["transaction_details.order_id sudah digunakan"]})
|
|
217
|
+
token = str(uuid.uuid4())
|
|
218
|
+
state.tokens[token] = order_id
|
|
219
|
+
return self.send(201, {"token": token, "redirect_url": f"http://{self.host()}/snap/v3/redirection/{token}"})
|
|
220
|
+
ptype = req.get("payment_type")
|
|
221
|
+
if ptype not in ("qris", "bank_transfer", "gopay"):
|
|
222
|
+
return self.send(400, {"status_code": "400", "status_message": "One or more parameters in the payload is invalid.",
|
|
223
|
+
"error_messages": ["payment_type is not supported by the mock"]})
|
|
224
|
+
extra = {}
|
|
225
|
+
if ptype == "bank_transfer":
|
|
226
|
+
bank = str((req.get("bank_transfer") or {}).get("bank") or "")
|
|
227
|
+
if bank not in ("bca", "bni", "bri", "cimb", "permata"):
|
|
228
|
+
return self.send(400, {"status_code": "400", "status_message": "One or more parameters in the payload is invalid.",
|
|
229
|
+
"error_messages": ["bank_transfer.bank is invalid"]})
|
|
230
|
+
va = "8127" + f"{int(hashlib.sha256(order_id.encode()).hexdigest(), 16) % 10**11:011d}"
|
|
231
|
+
extra = {"permata_va_number": va} if bank == "permata" else {"va_numbers": [{"bank": bank, "va_number": va}]}
|
|
232
|
+
if ptype == "qris":
|
|
233
|
+
extra = {"acquirer": str((req.get("qris") or {}).get("acquirer") or "gopay")}
|
|
234
|
+
o = self.new_order(order_id, amount, ptype, "pending", **extra)
|
|
235
|
+
if o is None:
|
|
236
|
+
return self.send(406, {"status_code": "406", "status_message": "The request could not be completed due to a conflict with the current state of the target resource, please try again",
|
|
237
|
+
"id": str(uuid.uuid4())})
|
|
238
|
+
tid, base = o["transaction_id"], f"http://{self.host()}"
|
|
239
|
+
exp = req.get("custom_expiry") or {}
|
|
240
|
+
minutes = int(exp.get("expiry_duration") or (1440 if ptype == "bank_transfer" else 15))
|
|
241
|
+
ans = {"status_code": "201", "transaction_id": tid, "order_id": order_id, "merchant_id": state.merchant_id,
|
|
242
|
+
"gross_amount": money(amount), "currency": "IDR", "payment_type": ptype, "transaction_time": o["time"],
|
|
243
|
+
"transaction_status": "pending", "fraud_status": "accept",
|
|
244
|
+
"expiry_time": (datetime.now(WIB) + timedelta(minutes=minutes)).strftime("%Y-%m-%d %H:%M:%S")}
|
|
245
|
+
ans.update(extra)
|
|
246
|
+
if ptype == "qris":
|
|
247
|
+
o["qr_string"] = f"00020101021226MOCK{tid.replace('-', '')}5303360540{len(str(amount))}{amount}5802ID6304MOCK"
|
|
248
|
+
ans.update({"status_message": "QRIS transaction is created", "qr_string": o["qr_string"],
|
|
249
|
+
"actions": [{"name": "generate-qr-code", "method": "GET", "url": f"{base}/v2/qris/{tid}/qr-code"}]})
|
|
250
|
+
elif ptype == "gopay":
|
|
251
|
+
o["qr_string"] = f"gopay-mock-{tid}"
|
|
252
|
+
ans.update({"status_message": "GO-PAY billing created",
|
|
253
|
+
"actions": [{"name": "generate-qr-code", "method": "GET", "url": f"{base}/v2/gopay/{tid}/qr-code"},
|
|
254
|
+
{"name": "deeplink-redirect", "method": "GET", "url": f"{base}/snap/v3/redirection/gopay-{tid}"},
|
|
255
|
+
{"name": "get-status", "method": "GET", "url": f"{base}/v2/{tid}/status"},
|
|
256
|
+
{"name": "cancel", "method": "POST", "url": f"{base}/v2/{tid}/cancel"}]})
|
|
257
|
+
else:
|
|
258
|
+
ans["status_message"] = "Success, Bank Transfer transaction is created"
|
|
259
|
+
return self.send(200, ans)
|
|
260
|
+
m = re.match(r"^/simulate/(pay|refund|resend)/(.+)$", u.path)
|
|
261
|
+
if m:
|
|
262
|
+
kind, order_id = m.group(1), urllib.parse.unquote(m.group(2))
|
|
263
|
+
o = state.orders.get(order_id)
|
|
264
|
+
if not o:
|
|
265
|
+
return self.send(404, {"error": "no such order"})
|
|
266
|
+
if kind == "pay":
|
|
267
|
+
status = q.get("status", ["settlement"])[0]
|
|
268
|
+
if status not in STATUS_CODE or status in ("refund", "partial_refund"):
|
|
269
|
+
return self.send(400, {"error": "status is settlement, capture, pending, deny, expire or cancel"})
|
|
270
|
+
if o["status"] in ("settlement", "capture", "refund", "partial_refund"):
|
|
271
|
+
return self.send(409, {"error": "already paid: use /simulate/resend for a repeated notification"})
|
|
272
|
+
if "payment_type" in q:
|
|
273
|
+
o["payment_type"] = q["payment_type"][0]
|
|
274
|
+
o["status"] = status
|
|
275
|
+
if status == "settlement":
|
|
276
|
+
o["settled"] = now_wib()
|
|
277
|
+
return self.send(200, {"notified": notify(state, order_id, o, status), "status": status})
|
|
278
|
+
if kind == "refund":
|
|
279
|
+
if o["status"] not in ("settlement", "capture", "partial_refund"):
|
|
280
|
+
return self.send(404, {"error": "not paid"})
|
|
281
|
+
if o["payment_type"] == "bank_transfer":
|
|
282
|
+
return self.send(412, {"status_code": "412", "status_message": "Merchant cannot modify the status of the transaction"})
|
|
283
|
+
left = o["gross_amount"] - o["refunded"]
|
|
284
|
+
amount = int(q.get("amount", [str(left)])[0])
|
|
285
|
+
if amount <= 0 or amount > left:
|
|
286
|
+
return self.send(400, {"error": "amount is more than what is left to refund"})
|
|
287
|
+
o["refunded"] += amount
|
|
288
|
+
o["status"] = "refund" if o["refunded"] == o["gross_amount"] else "partial_refund"
|
|
289
|
+
code = notify(state, order_id, o, o["status"], refund_amount=money(o["refunded"]),
|
|
290
|
+
refunds=[{"refund_chargeback_id": 1, "refund_amount": money(amount), "created_at": now_wib(),
|
|
291
|
+
"reason": "refund from the mock", "refund_key": "refund-" + uuid.uuid4().hex[:10]}])
|
|
292
|
+
return self.send(200, {"notified": code, "status": o["status"], "amount": amount})
|
|
293
|
+
if not o.get("last"):
|
|
294
|
+
return self.send(404, {"error": "nothing was notified for this order"})
|
|
295
|
+
return self.send(200, {"notified": post(state.notify_url, o["last"]), "status": o["last"]["transaction_status"]})
|
|
296
|
+
if u.path == "/simulate/notify":
|
|
297
|
+
try:
|
|
298
|
+
req = json.loads(raw or b"{}")
|
|
299
|
+
order_id, status = str(req["order_id"]), str(req.get("transaction_status", "settlement"))
|
|
300
|
+
o = {"transaction_id": str(req.get("transaction_id") or uuid.uuid4()), "gross_amount": int(req["gross_amount"]),
|
|
301
|
+
"payment_type": str(req.get("payment_type", "qris")), "time": now_wib(), "extra": {}}
|
|
302
|
+
more = {k: req[k] for k in ("fraud_status", "status_code", "refund_amount") if k in req}
|
|
303
|
+
if "status_code" in more: # a chosen status code is signed as sent
|
|
304
|
+
more["signature_key"] = sign(order_id, str(more["status_code"]), money(o["gross_amount"]), state.server_key)
|
|
305
|
+
except (ValueError, KeyError, TypeError):
|
|
306
|
+
return self.send(400, {"error": "order_id and gross_amount are needed"})
|
|
307
|
+
return self.send(200, {"notified": post(state.notify_url, body_of(state, order_id, o, status, **more))})
|
|
308
|
+
self.send(404, {"status_code": "404", "status_message": "The requested resource is not found"})
|
|
309
|
+
return H
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def dummy_key(key: str) -> bool:
|
|
313
|
+
"""True for a key that says it is a dummy: the mock signs whatever it is asked, so a real key must never reach it."""
|
|
314
|
+
return bool(re.search(r"(^|[-_.])(dummy|test)([-_.]|$)", key, re.IGNORECASE))
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def main(argv=None):
|
|
318
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
319
|
+
ap.add_argument("--port", type=int, default=8903)
|
|
320
|
+
ap.add_argument("--notify-url", required=True, help="the kernel hook: http://<kernel>/hooks/<org>/midtrans/payment_notified")
|
|
321
|
+
a = ap.parse_args(argv)
|
|
322
|
+
key = os.environ.get("MIDTRANS_MOCK_SERVER_KEY") or ""
|
|
323
|
+
if not dummy_key(key):
|
|
324
|
+
ap.error("set MIDTRANS_MOCK_SERVER_KEY to a dummy key (a part dummy or test, e.g. SB-Mid-server-dummy-demo); never a real Midtrans key")
|
|
325
|
+
srv = ThreadingHTTPServer(("127.0.0.1", a.port), handler(State(key, a.notify_url)))
|
|
326
|
+
print(f"midtrans mock on http://127.0.0.1:{srv.server_address[1]} (notifications to {a.notify_url})", flush=True)
|
|
327
|
+
try:
|
|
328
|
+
srv.serve_forever()
|
|
329
|
+
except KeyboardInterrupt:
|
|
330
|
+
pass
|
|
331
|
+
return 0
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
if __name__ == "__main__":
|
|
335
|
+
sys.exit(main())
|