# Wallet & Withdrawal API Documentation ## Table of Contents 1. [Midtrans Payment](#midtrans-payment) 2. [Wallet Management](#wallet-management) 3. [Bank Account Management](#bank-account-management) 4. [Withdrawal Management](#withdrawal-management) 5. [Admin Withdrawal Management](#admin-withdrawal-management) ## Midtrans Payment ### Initiate Midtrans Payment ```http POST /api/bookings/{booking}/midtrans/pay ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": { "snap_token": "66e4fa55-fdac-4ef9-91b5-733b97d1b862", "redirect_url": "https://app.sandbox.midtrans.com/snap/v2/vtweb/66e4fa55-fdac-4ef9-91b5-733b97d1b862", "booking": { "id": 1, "transaction_code": "TRX-20240503-A1B2C3", "total_price": 150000, "status": "selesai" } }, "message": "Token pembayaran berhasil dibuat" } ``` ### Check Payment Status ```http GET /api/bookings/{booking}/payment-status ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": { "booking_id": 1, "transaction_code": "TRX-20240503-A1B2C3", "payment_status": "pending", "payment_method": "bank_transfer", "total_price": 150000, "status": "selesai", "midtrans_snap_token": "66e4fa55-fdac-4ef9-91b5-733b97d1b862" }, "message": "Status pembayaran berhasil diambil" } ``` ### Manual Check and Update Payment Status ```http POST /api/bookings/{booking}/payment-status/check ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": { "booking_id": 1, "transaction_code": "TRX-20240503-A1B2C3", "payment_status": "paid", "payment_method": "bank_transfer", "total_price": 150000, "status": "selesai", "midtrans_status": "settlement", "midtrans_snap_token": "66e4fa55-fdac-4ef9-91b5-733b97d1b862" }, "message": "Status pembayaran berhasil diperbarui" } ``` ## Wallet Management ### Get Wallet Information ```http GET /api/wallet ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": { "balance": 1000000.00, "pending_withdrawals": 300000.00, "available_balance": 700000.00, "transactions": [ { "id": 1, "type": "credit", "amount": 500000.00, "description": "Pembayaran booking #TRX-001", "status": "success", "created_at": "2024-05-03T10:00:00.000000Z", "booking": { "id": 1, "transaction_code": "TRX-001", "service_type": "jahit", "category": "baju" } } ] }, "message": "Wallet information retrieved successfully" } ``` ## Bank Account Management ### Register Bank Account ```http POST /api/bank-accounts ``` **Headers:** ``` Authorization: Bearer {token} Content-Type: application/json ``` **Request Body:** ```json { "bank_name": "BCA", "account_number": "1234567890", "account_holder_name": "John Doe" } ``` **Response:** ```json { "success": true, "data": { "id": 1, "bank_name": "BCA", "account_number": "1234567890", "account_holder_name": "John Doe", "status": "pending", "created_at": "2024-05-03T10:00:00.000000Z" }, "message": "Bank account registered successfully" } ``` ### Verify Bank Account (Admin Only) ```http POST /api/admin/bank-accounts/{bankAccount}/verify ``` **Headers:** ``` Authorization: Bearer {token} Content-Type: application/json ``` **Request Body:** ```json { "status": "active", "rejection_reason": null } ``` **Response:** ```json { "success": true, "data": { "id": 1, "bank_name": "BCA", "account_number": "1234567890", "account_holder_name": "John Doe", "status": "active", "verified_at": "2024-05-03T10:00:00.000000Z", "updated_at": "2024-05-03T10:00:00.000000Z" }, "message": "Bank account verification completed" } ``` ## Withdrawal Management ### Request Withdrawal ```http POST /api/withdrawals ``` **Headers:** ``` Authorization: Bearer {token} Content-Type: application/json ``` **Request Body:** ```json { "bank_account_id": 1, "amount": 500000 } ``` **Response:** ```json { "success": true, "data": { "withdrawal": { "id": 1, "wallet_id": 1, "bank_account_id": 1, "amount": 500000.00, "status": "pending", "created_at": "2024-05-03T10:00:00.000000Z" }, "wallet": { "balance": 1000000.00, "pending_withdrawals": 500000.00, "available_balance": 500000.00 } }, "message": "Withdrawal request submitted successfully" } ``` **Error Response - Insufficient Balance:** ```json { "success": false, "data": { "balance": 1000000.00, "pending_withdrawals": 800000.00, "available_balance": 200000.00, "requested_amount": 500000.00 }, "message": "Insufficient available balance." } ``` ### Get Withdrawal History ```http GET /api/withdrawals ``` **Headers:** ``` Authorization: Bearer {token} ``` **Query Parameters:** - `status` (optional) - Filter by withdrawal status. Allowed values: "pending", "processing", "completed", "rejected" **Response:** ```json { "success": true, "data": [ { "id": 1, "amount": 500000.00, "status": "completed", "created_at": "2024-05-03T10:00:00.000000Z", "processed_at": "2024-05-03T11:00:00.000000Z", "bank_account": { "bank_name": "BCA", "account_number": "1234567890", "account_holder_name": "John Doe" } } ], "message": "Withdrawal history retrieved successfully" } ``` ## Admin Withdrawal Management ### Get Pending Withdrawals ```http GET /api/admin/withdrawals/pending ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": [ { "id": 1, "amount": 500000.00, "status": "pending", "created_at": "2024-05-03T10:00:00.000000Z", "wallet": { "user": { "id": 1, "name": "John Doe", "email": "john@example.com" } }, "bank_account": { "bank_name": "BCA", "account_number": "1234567890", "account_holder_name": "John Doe" } } ], "message": "Pending withdrawals retrieved successfully" } ``` ### Get Pending Bank Accounts ```http GET /api/admin/bank-accounts/pending ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": [ { "id": 1, "user_id": 2, "bank_name": "BCA", "account_number": "1234567890", "account_holder_name": "John Doe", "status": "pending", "created_at": "2024-05-03T10:00:00.000000Z", "updated_at": "2024-05-03T10:00:00.000000Z", "user": { "id": 2, "name": "John Doe", "email": "john@example.com", "role": "penjahit" } } ], "message": "Pending bank accounts retrieved successfully" } ``` ### Process Withdrawal ```http POST /api/admin/withdrawals/{withdrawal}/process ``` **Headers:** ``` Authorization: Bearer {token} Content-Type: multipart/form-data ``` **Request Body:** ```json { "status": "processing", "proof_of_payment": [file] } ``` **Response:** ```json { "success": true, "data": { "id": 1, "amount": 500000.00, "status": "processing", "proof_of_payment": "proof_of_payments/abc123.jpg", "updated_at": "2024-05-03T11:00:00.000000Z" }, "message": "Withdrawal status updated successfully" } ``` ### Complete Withdrawal ```http POST /api/admin/withdrawals/{withdrawal}/complete ``` **Headers:** ``` Authorization: Bearer {token} ``` **Response:** ```json { "success": true, "data": { "id": 1, "amount": 500000.00, "status": "completed", "processed_at": "2024-05-03T12:00:00.000000Z", "updated_at": "2024-05-03T12:00:00.000000Z" }, "message": "Withdrawal completed successfully" } ``` ## Error Responses ### Validation Error ```json { "success": false, "data": { "bank_name": ["The bank name field is required."], "account_number": ["The account number field is required."] }, "message": "Validation Error." } ``` ### Insufficient Balance ```json { "success": false, "data": { "error": "Insufficient balance." }, "message": "Error." } ``` ### Invalid Bank Account ```json { "success": false, "data": { "error": "Invalid bank account." }, "message": "Error." } ``` ## Status Codes - 200: Success - 201: Created - 400: Bad Request - 401: Unauthorized - 403: Forbidden - 404: Not Found - 422: Validation Error - 500: Server Error