meta {
  name: Create Xendit Invoice
  type: http
  seq: 3
}

post {
  url: {{baseUrl}}/payment/{{paymentId}}/xendit-invoice
  body: json
  auth: bearer
}

headers {
  Content-Type: application/json
}

auth:bearer {
  token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzc2MzMxMTM1LCJleHAiOjE3NzYzMzQ3MzV9.JdiHIu4v4wekkiqbsCaAR2NTHUFwF-AZe93dFwhsySw
}

body:json {
  {
    "customer_name": "{{customerName}}",
    "payer_email": "{{payerEmail}}",
    "mobile_number": "{{mobileNumber}}"
  }
}

vars:pre-request {
  customerName: adi
  payerEmail: adi.edwinconsultants@gmail.com
  mobileNumber: 081235367882
  baseUrl: https://whatsapp-dev.edwinconsultants.com:9443
  paymentId: 195
}

script:post-response {
  const data = res.getBody();
  if (data && data.data) {
    if (data.data.xendit_invoice_id) {
      bru.setEnvVar("xenditInvoiceId", data.data.xendit_invoice_id);
    }
    if (data.data.xendit_external_id) {
      bru.setEnvVar("xenditExternalId", data.data.xendit_external_id);
    }
  }
}
