{"openapi":"3.0.3","info":{"title":"Affiliate API","description":"API for the Shopify Proxy-based affiliate program.\n\n## Authentication\nAll endpoints require three query parameters for authentication:\n- `email` — Logged-in customer's email\n- `_customer_id` — Shopify customer ID\n- `_hmac` — HMAC signature for verification\n\n### How to Calculate HMAC\n```\nhmac_sha256(lowercase(\"{customer_id}:{email}:{YYYY-MM-DD}\"), SHOPIFY_HMAC_SECRET)\n```\n**Example input before hashing:**\n```\n10234:user@example.com:2026-04-30\n```\n\nIf the HMAC is invalid, the system returns `401 Unauthorized`.\n\n**Rate Limit:** 30 requests per minute per client IP.\n","version":"1.0.0","contact":{}},"servers":[{"description":"SwaggerHub API Auto Mocking","url":"https://virtserver.swaggerhub.com/ABELHENRYAN/Atambah/1.0.0"},{"description":"Dev Atambah","url":"https://dev-atambah.sunny.co.id"},{"description":"Local Abel","url":"https://edmond-gravimetric-rosaura.ngrok-free.dev"}],"tags":[{"name":"Auth & Status","description":"Check affiliate status"},{"name":"Registration","description":"Register as a new affiliate"},{"name":"Account","description":"Manage affiliate account"},{"name":"Payout","description":"Withdraw commission balance"},{"name":"Commission","description":"Commission history"}],"paths":{"/api/shopify-proxy/check":{"get":{"tags":["Auth & Status"],"summary":"Check affiliate status","description":"Checks the affiliate status of the currently logged-in customer.\n\n**Flow:**\n1. Email is read from `_verified_email` injected by the middleware.\n2. The system looks up the contact by email. If not found, falls back to lookup by phone.\n3. If contact is found but `is_affiliate = false`, returns a minimal response.\n4. If an active affiliate is found, returns full data.\n","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"responses":{"200":{"description":"Affiliate status retrieved successfully","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/CheckResponseNotAffiliate"},{"$ref":"#/components/schemas/CheckResponseAffiliate"}]},"examples":{"not_affiliate":{"summary":"Customer is not an affiliate","value":{"is_affiliate":false,"contact":null,"affiliate":null}},"active_affiliate":{"summary":"Customer is an active affiliate","value":{"is_affiliate":true,"status":"Active","commission_balance":250000,"bank_name":"BCA","bank_account_number":"1234567890","bank_account_name":"John Doe","start_date":"2025-01-01","end_date":null,"has_pending_payout":false,"referral_link":"https://store.example.com?ref=JOHNDOE"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/shopify-proxy/register":{"post":{"tags":["Registration"],"summary":"Register as an affiliate","description":"Registers a Shopify customer as a new affiliate.","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegisterRequest"},"example":{"phone":"08123456789","bank_name":"BCA","bank_number":"1234567890","bank_holder":"John Doe"}}}},"responses":{"201":{"description":"Affiliate registered successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"},"example":{"success":true,"message":"Affiliate registered successfully."}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"description":"Contact not found by email or phone","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"Contact not found by email or phone."}}}},"422":{"description":"Customer is already registered as an affiliate","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"Customer is already registered as an affiliate."}}}},"500":{"$ref":"#/components/responses/InternalServerError"}}}},"/api/shopify-proxy/update-information":{"put":{"tags":["Account"],"summary":"Update bank information","description":"Updates the bank information of the currently logged-in affiliate.\n\nAll fields are nullable. Only fields that are sent will be updated.\n","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateBankRequest"},"example":{"bank_name":"Mandiri","bank_account_name":"John Doe","bank_account_number":"9876543210"}}}},"responses":{"200":{"description":"Information updated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"},"example":{"success":true,"message":"Information updated successfully."}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/shopify-proxy/resign":{"put":{"tags":["Account"],"summary":"Resign from affiliate program","description":"Resigns the current user from the affiliate program. No request body required.\n\n**Flow:**\n1. Email is read from `_verified_email`.\n2. The system finds the active affiliate by email.\n3. `affiliate_status` is set to `\"Terminated\"`.\n4. `contact.is_affiliate` is set to `false`.\n","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"responses":{"200":{"description":"Successfully resigned from the affiliate program","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"},"example":{"success":true,"message":"You have successfully resigned from the affiliate program."}}}},"401":{"description":"Email not found in request (middleware injection failed) or invalid HMAC","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"Unauthorized."}}}},"422":{"description":"No active affiliate found for this email","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"No active affiliate found for this email."}}}}}}},"/api/shopify-proxy/payout":{"post":{"tags":["Payout"],"summary":"Submit payout request","description":"Submits a commission balance withdrawal request.","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutRequest"},"example":{"amount":150000}}}},"responses":{"200":{"description":"Payout request submitted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutResponse"},"example":{"message":"Payout request submitted successfully.","request_code":"PAY-20260430-0042","requested_amount":150000}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"description":"Insufficient balance or pending payout already exists","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"examples":{"insufficient_balance":{"summary":"Insufficient commission balance","value":{"message":"Insufficient commission balance."}},"pending_payout":{"summary":"Pending payout already exists","value":{"message":"A payout request is already pending."}}}}}}}}},"/api/shopify-proxy/payout-history":{"get":{"tags":["Payout"],"summary":"Get payout history","description":"Returns the last 5 payout requests of the currently logged-in affiliate.\n\nSorted from most recent. Returns an empty array if no active affiliate is found.\n","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"responses":{"200":{"description":"Payout history retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayoutHistoryResponse"},"example":{"payouts":[{"request_code":"PAY-20260430-0042","requested_amount":150000,"date_requested":"2026-04-30","date_paid":null,"date_rejected":null,"stage":"Pending"},{"request_code":"PAY-20260310-0018","requested_amount":200000,"date_requested":"2026-03-10","date_paid":"2026-03-12","date_rejected":null,"stage":"Paid"}]}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/shopify-proxy/payout-request/cancel":{"post":{"tags":["Payout"],"summary":"Cancel payout request","description":"Cancels a payout request that is still in pending status.","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelPayoutRequest"},"example":{"shopify_member_id":"gid://shopify/Customer/987654321","email":"user@example.com"}}}},"responses":{"200":{"description":"Payout request cancelled successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"},"example":{"success":true,"message":"Payout request has been cancelled successfully."}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"description":"Cancellation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"Request not found, does not belong to this user, or is no longer in pending status."}}}}}}},"/api/shopify-proxy/commissions":{"get":{"tags":["Commission"],"summary":"Get commission history","description":"Returns the last 5 commission records of the currently logged-in affiliate.\n\nSorted from most recent. Returns an empty array if no active affiliate is found.\n","parameters":[{"$ref":"#/components/parameters/EmailParam"},{"$ref":"#/components/parameters/CustomerIdParam"},{"$ref":"#/components/parameters/HmacParam"},{"$ref":"#/components/parameters/NgrokSkipParam"}],"responses":{"200":{"description":"Commission history retrieved successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommissionHistoryResponse"},"example":{"commissions":[{"amount":500000,"net_amount":50000,"commission_status":"Approved","created_at":"2026-04-15T10:23:00Z"},{"amount":250000,"net_amount":25000,"commission_status":"Pending","created_at":"2026-04-28T14:05:33Z"}]}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}}},"components":{"parameters":{"EmailParam":{"name":"email","in":"query","required":true,"description":"Logged-in customer's email","schema":{"type":"string","format":"email","example":"user@example.com"}},"CustomerIdParam":{"name":"_customer_id","in":"query","required":true,"description":"Shopify customer ID","schema":{"type":"string","example":"10234"}},"HmacParam":{"name":"_hmac","in":"query","required":true,"description":"HMAC signature (hmac_sha256 of \"{customer_id}:{email}:{YYYY-MM-DD}\")","schema":{"type":"string","example":"a3f8c2d1e4b5..."}},"NgrokSkipParam":{"name":"ngrok-skip-browser-warning","in":"header","required":false,"schema":{"type":"string","default":"true"}}},"schemas":{"SuccessResponse":{"type":"object","properties":{"success":{"type":"boolean","example":true},"message":{"type":"string","example":"Operation successful."}}},"ErrorResponse":{"type":"object","properties":{"message":{"type":"string","example":"An error occurred."}}},"CheckResponseNotAffiliate":{"type":"object","properties":{"is_affiliate":{"type":"boolean","example":false},"contact":{"nullable":true,"example":null},"affiliate":{"nullable":true,"example":null}}},"CheckResponseAffiliate":{"type":"object","properties":{"is_affiliate":{"type":"boolean","example":true},"status":{"type":"string","example":"Active"},"commission_balance":{"type":"integer","example":250000},"bank_name":{"type":"string","example":"BCA"},"bank_account_number":{"type":"string","example":"1234567890"},"bank_account_name":{"type":"string","example":"John Doe"},"start_date":{"type":"string","format":"date","example":"2025-01-01"},"end_date":{"type":"string","format":"date","nullable":true,"example":null},"has_pending_payout":{"type":"boolean","example":false},"referral_link":{"type":"string","example":"https://store.example.com?ref=JOHNDOE"}}},"RegisterRequest":{"type":"object","required":["bank_name","bank_number","bank_holder"],"properties":{"phone":{"type":"string","example":"08123456789"},"bank_name":{"type":"string","example":"BCA"},"bank_number":{"type":"string","example":"1234567890"},"bank_holder":{"type":"string","example":"John Doe"}}},"UpdateBankRequest":{"type":"object","properties":{"bank_name":{"type":"string","nullable":true,"example":"Mandiri"},"bank_account_name":{"type":"string","nullable":true,"example":"John Doe"},"bank_account_number":{"type":"string","nullable":true,"example":"9876543210"}}},"PayoutRequest":{"type":"object","required":["amount"],"properties":{"amount":{"type":"integer","minimum":100000,"example":150000,"description":"Amount to withdraw, minimum Rp 100,000"}}},"PayoutResponse":{"type":"object","properties":{"message":{"type":"string","example":"Payout request submitted successfully."},"request_code":{"type":"string","example":"PAY-20260430-0042"},"requested_amount":{"type":"integer","example":150000}}},"PayoutHistoryResponse":{"type":"object","properties":{"payouts":{"type":"array","items":{"$ref":"#/components/schemas/PayoutItem"}}}},"PayoutItem":{"type":"object","properties":{"request_code":{"type":"string","example":"PAY-20260430-0042"},"requested_amount":{"type":"integer","example":150000},"date_requested":{"type":"string","format":"date","example":"2026-04-30"},"date_paid":{"type":"string","format":"date","nullable":true,"example":null},"date_rejected":{"type":"string","format":"date","nullable":true,"example":null},"stage":{"type":"string","enum":["Pending","Paid","Rejected"],"example":"Pending"}}},"CancelPayoutRequest":{"type":"object","required":["shopify_member_id","email"],"properties":{"shopify_member_id":{"type":"string","example":"gid://shopify/Customer/987654321"},"email":{"type":"string","format":"email","example":"user@example.com"}}},"CommissionHistoryResponse":{"type":"object","properties":{"commissions":{"type":"array","items":{"$ref":"#/components/schemas/CommissionItem"}}}},"CommissionItem":{"type":"object","properties":{"amount":{"type":"integer","example":500000},"net_amount":{"type":"integer","example":50000},"commission_status":{"type":"string","enum":["Pending","Approved","Rejected"],"example":"Approved"},"created_at":{"type":"string","format":"date-time","example":"2026-04-15T10:23:00Z"}}}},"responses":{"Unauthorized":{"description":"Invalid HMAC or incomplete authentication parameters","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"Unauthorized."}}}},"InternalServerError":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"message":"Internal server error."}}}}}}}