# BillLoader API for PayZave
## Environment
> Testing : ***https://bill-loader-api-test.builk.com/swagger/index.html***
> UAT : ***https://bill-loader-api-uat.builk.com/swagger/index.html***
> Production :
>> ตัวอย่าง Request โดย Postman ***https://www.getpostman.com/collections/5feca9a72736a7b534cd***
## Authorization Method
> การยืนยันตัวตนสำหรับการเรียกใช้งานในทุกๆ API ต้องแนบ Header Request ดังต่อไปนี้
**Header Request**
| Parameter | Description | Schema |
| -------------------------- | ------------------------------------------ | ------- |
| authorization (*required*) | JWT Token start with "Bearer " |string |
> โดยสามารถได้รับจากการเรียกใช้งาน API `/api/v1/Authentication/OpenApiAuthentication`
### Authentication data
| Environment | Endpoint | Username | Password | Initial authString |
| ------------- | --------------------------------------- | ---------- | ---------- | ------------------ |
| Testing | https://bill-loader-api-test.builk.com | payzave-demo | 7kp2Mm7tb6 | PycqNcXk305I4g7hCZRPla7+1oRbMmH6jSIYSZWij4/ia8SAx4kCX9Y1xRrmyRHEcXv2kT8/HG/MDLeIjnWhaW4JcCmJetqIuEVyQHZxNc4qJg83mydNZzDqrBwsTAEolFs9rbNgBGilqPTEIh8fh1/uyc31V+0c74gJRhg7UpuILEp//fzQ9nq0dlVSK2t1Ch51YOulRG7465WRkj6+6CcZlBojdrKfrul5gZpDRPMDZ0hw8o2lARVr4PyIukTNCXfX5IOCZtkK7WVo/8k3ooO/WlX9UdRAxXbGkwlNx+ZufrQUFrIWJ+KkuNRPfq3dztfJ7ffLkuVa1kYFAaV5Mg== |
| User acceptance test | https://bill-loader-api-uat.builk.com | payzave-uat | vU1GcqSRrF | LXER2n8x6zhO4fGDFDA0ZhuCx2N8V/F2LIEyuIadcHk7GdhPxM7W8vLx/w8ySIjCHjC0ck1/9a9fhkITm3vyJZqWu12kYd/A/mcO6ZpClWN/lDkUe9Duvnr+nZ58Hl9u+uqVyFk4DzH7300rum160pKruIbTSVyWhLtBGJrZ+WjZwZevvLOEw2k5YQcp6olAzlgG4v2cjEuoi4KbwqZXQDkMYbsVo09+8xChl7xZpa6tvo86PQWJaABcMS0LvvjssRbjDxSMvLZvpDS8DKsf6LLnCLTrEI+2nydc//XEJIEv1+FGyEBpsrgf5wbFCS933cANplxI/V3SxLG0K7f4og== |
### `POST /api/v1/Authentication/OpenApiAuthentication`
**Body Request**
| Parameter | Description | Schema |
| ----------------- | ------------------ | ------ |
| authString | encyp string | string |
**Response**
| Parameter | Description | Schema |
| ----------- | ----------------- | ------ |
| data | object return | object |
| status | | number |
| message | detail of error | string |
**Object**
| Parameter | Description | Schema |
| ----------- | ----------------------------------------------- | ------ |
| accessToken | jwt token for attachment in header every request | object |
| expiredToken | expired of token in format unix time | number |
#### Example Request
```
"PycqNcXk305I4g7hCZRPla7+1oRbMmH6jSIYSZWij4/ia8SAx4kCX9Y1xRrmyRHEcXv2kT8/HG/MDLeIjnWhaW4JcCmJetqIuEVyQHZxNc4qJg83mydNZzDqrBwsTAEolFs9rbNgBGilqPTEIh8fh1/uyc31V+0c74gJRhg7UpuILEp//fzQ9nq0dlVSK2t1Ch51YOulRG7465WRkj6+6CcZlBojdrKfrul5gZpDRPMDZ0hw8o2lARVr4PyIukTNCXfX5IOCZtkK7WVo/8k3ooO/WlX9UdRAxXbGkwlNx+ZufrQUFrIWJ+KkuNRPfq3dztfJ7ffLkuVa1kYFAaV5Mg=="
```
#### Example Response
```json
{
"code": 200,
"message": "Success",
"timestamp": "2021-02-22T06:21:48.5741764Z",
"data": {
"accessToken": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJGYWN0b3JpbmdHdWlkIjoiZDgyZjdjN2MtYTljOS00NmNjLTk0YzItYzI3ODk5NDJkOGQ4IiwibmJmIjoxNjEzOTc0OTA4LCJleHAiOjE2MTM5Nzg1MDgsImlhdCI6MTYxMzk3NDkwOCwiaXNzIjoiYmlsbC1sb2FkZXIuYnVpbGsuY29tIiwiYXVkIjoiZXh0ZXJuYWwtYXV0aC1zZXJ2aWNlIn0.aJ_OdlWP9rJGq_96casoGM5DHv10cyshVDykGbMeMy0",
"expiredToken": 1613978508
}
}
```
---
> โดย authString ได้จากการนำ Json body มาเข้ารหัสชนิด RSA ขนาด 2048
> โดยมีเราทำการ generate authString เบื้องต้นไว้ให้ โดยมีเงื่อนไขเวลาหมดอายุของ token ที่ 15 นาที (900 วินาที)
> > PycqNcXk305I4g7hCZRPla7+1oRbMmH6jSIYSZWij4/ia8SAx4kCX9Y1xRrmyRHEcXv2kT8/HG/MDLeIjnWhaW4JcCmJetqIuEVyQHZxNc4qJg83mydNZzDqrBwsTAEolFs9rbNgBGilqPTEIh8fh1/uyc31V+0c74gJRhg7UpuILEp//fzQ9nq0dlVSK2t1Ch51YOulRG7465WRkj6+6CcZlBojdrKfrul5gZpDRPMDZ0hw8o2lARVr4PyIukTNCXfX5IOCZtkK7WVo/8k3ooO/WlX9UdRAxXbGkwlNx+ZufrQUFrIWJ+KkuNRPfq3dztfJ7ffLkuVa1kYFAaV5Mg==
>
> ซึ่งถ้าต้องการ custom token expired ให้ทำการสร้าง Json Body ดังนี้
**Json Body**
| Parameter | Description | Schema |
| ----------------- | ------------------ | ------ |
| userName | | string |
| password | | string |
| expiredRequest | age of token unit is second | number |
```json
{
"userName": "payzave-demo",
"password": "7kp2Mm7tb6",
"expiredRequest": 3600
}
```
> และทำการเข้ารหัสด้วย RSA 2048 Public key
```xml
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgHD0cv4PdB3yTNL3eJZC
72VZ6AWRjxg/tv4p1s53/2uzcN1HJjKkcnklO6h7w6AZB9WXnXaiwemJux7oDGsq
Ett1Ejx9ayGUI30iKy7WE40Aw5fHKDNWNP2LXTDJ6P6JQhY4kp4T3od3R2ESHCau
VHWelX6+OE8XoPoa5f48/yfQoPcVl/Y/Ig9gNEovT57B6fhp7wM2YKgronaQS1+X
6jqLIryRDkNW6nhJDuTNGx2kCckq/AWzHlSb7Iooi6Iqhy4ZmF+sJhQzhvesaz//
VgnPN06UIbfbo0yVfKhx2JwGYuVJSXzpv0Z5MiD685Jp5LRpaYuxVRRCwqfaVO8s
6wIDAQAB
-----END PUBLIC KEY-----
```
## Data Api
### `POST /api/v1/External/PayZave/IssuePayment`
**Body Request**
| Parameter | Description | Schema |
| -------------------------------------- | ------------------------------------------------------------------------------------- | ------ |
| requestId (*required*) | SpanID from PayZave (max lenght 255) | string |
| paymentNumber (*required*) | Format: "PAY-" + running number Payment Number generated from PayZave (max lenght 255) | string |
| paymentDate (*required*) | Payment date (format YYYY-MM-DD or ISO format) | date |
| buyerCode (*optional*) | Buyer company code (max lenght 35) | string |
| buyerTaxId (*required*) | Buyer company tax ID (max lenght 35) | string |
| sellerCode (*optional*) | Seller company code (max lenght 35) | string |
| sellerTaxId (*required*) | Seller company tax ID (max lenght 35) | string |
| paymentToSellerNetAmount (*required*) | Actual payment to seller (bank out) from buyer (max range 9999999999999999.99) | number |
| buyerBankAccountNumber (*required*) | Buyer bank account number (max lenght 35) | string |
| buyerBankAccountName (*required*) | Buyer bank account name (max lenght 255) | string |
| buyerBankCode (*required*) | Buyer bank code (max lenght 3) | string |
| buyerBankBranchCode (*required*) | Buyer bank branch code (max lenght 35) | string |
| documentList (*required*) | array of object Document list | object |
**Document list object**
| Parameter | Description | Schema |
| -------------------------------------- | ------------------------------------------------------------------------------------- | ------ |
| documentType (*required*) | Type of document 'BL, INV, CN, DN' (max lenght 35) (now accept only BL type ) | string |
| documentNumber (*required*) | Seller Document number (Billing, Invoice, CN or DN number) (max lenght 35) | string |
| documentDate (*required*) | Seller Document date (format YYYY-MM-DD or ISO format) | string |
| currency (*required*) | Money currency (supported only THB) (max lenght 3) | string |
| originalAmount (*required*) | Original amount of Document (original invoice net amount included VAT, WHT deducted and other deduction) (max range 9999999999999999.99) | string |
| discountAmount (*required*) | Discount amount included platform fee (discount amount from request) (max range 9999999999999999.99)| string |
| buyerDocRef1 (*optional*) | Buyer Document Ref Number 1 | string |
| buyerDocRef2 (*optional*) | Buyer Document Ref Number 2 | string |
**Response**
| Parameter | Description | Schema |
| ----------- | ----------------------------------------------------------------------------- | ------ |
| data | data object | object |
| status | status of request (http status in header request will only return 200 ) | number |
| message | detail of error or 'success' | string |
**Data object**
| Parameter | Description | Schema |
| ------------------------ | --------------------------------------------------- | ------ |
| paymentNumber | PayZave payment number | string |
| buyerPaymentDocNumber | Buyer Payment Document number (have data when 200) | string |
| buyerPaymentDocRef1 | Buyer Payment Document Ref Number 1 | string |
| buyerPaymentDocRef2 | Buyer Payment Document Ref Number 2 | string |
#### Example Request
```json
{
"requestId": "2485ec27856c56f4",
"paymentNumber": "PAY-1",
"paymentDate": "2021-02-22T08:54:03.705Z",
"buyerCode": "0010",
"buyerTaxId": "01234567890123",
"sellerCode": "0002",
"sellerTaxId": "01234567890134",
"paymentToSellerNetAmount": 800,
"buyerBankAccountNumber": "1234567890",
"buyerBankAccountName": "บริษัท รับส่วนลด จำกัด",
"buyerBankCode": "014",
"buyerBankBranchCode": "0001",
"documentList": [
{
"documentType": "BL"",
"documentNumber": "INV010101",
"documentDate": "2021-02-22T08:54:03.705Z",
"currency": "THB",
"originalAmount": 15000,
"paymentAmount": 1000.00,
"discountAmount": 200,
"buyerDocNumber": "333f6354-79a6-4895-8941-98208f821f59",
"buyerDocRef1": "test1",
"buyerDocRef2": "test2"
},{
"documentType": "BL"",
"documentNumber": "INV010102",
"documentDate": "2021-02-22T08:54:03.705Z",
"currency": "THB",
"originalAmount": 15000,
"paymentAmount": 1000.00,
"discountAmount": 200,
"buyerDocNumber": "333f6354-79a6-4895-8941-98208f821f59",
"buyerDocRef1": "test1",
"buyerDocRef2": "test2"
}
]
}
```
#### Example Response
```json
{
"code": 200,
"message": "success",
"timestamp": "2021-02-22T08:54:03.705Z",
"data": {
"paymentNumber": "PAY-1",
"buyerPaymentDocNumber": "3b345478-1b72-4928-84d6-6abda48b3f3f",
"buyerPaymentDocRef1": "2020",
"buyerPaymentDocRef2": "ref2"
}
}
```
### `POST /api/v1/External/PayZave/ReversePayments`
**Body Request**
| Parameter | Description | Schema |
| -------------------------------------- | ------------------------------------------------------------------------------------------- | ------ |
| requestId (*required*) | SpanID from PayZave (max lenght 255) | string |
| buyerPaymentDocNumber (*required*) | Buyer Payment issue document number (original payment document number) (max lenght 50) | string |
| buyerPaymentDocRef1 (*required*) | Buyer Payment Document Ref Number 1 (e.g. Fiscal Year of Payment Document ) (max lenght 255) | date |
| buyerPaymentDocRef2 (*optional*) | Buyer Payment Document Ref Number 2 (e.g. Fiscal Year of Payment Document ) (max lenght 255) | string |
| buyerCode (*required*) | Buyer company code (max lenght 35) | string |
| buyerTaxId (*required*) | Buyer company tax ID (max lenght 35) | string |
| reverseMessage (*required*) | Bank (SCB) error message information (max lenght 255) | string |
**Response**
| Parameter | Description | Schema |
| ----------- | ----------------------------------------------------------------------------- | ------ |
| data | data object | object |
| status | status of request (http status in header request will only return 200 ) | number |
| message | detail of error or 'success' | string |
**Data object**
| Parameter | Description | Schema |
| ----------------------------- | ----------------------------------------------------------------------------------- | ------ |
| buyerReversalPaymentDocNumber | Buyer Payment reverse document number | string |
| buyerReversalPaymentDocRef1 | Buyer Payment reverse document Ref Number 1 (e.g. Fiscal Year of Payment Document ) | string |
| buyerReversalPaymentDocRef2 | Buyer Payment reverse document Ref Number 1 (e.g. Fiscal Year of Payment Document ) | string |
#### Example Request
```json
{
"requestId": "2485ec27856c5694",
"buyerPaymentDocNumber": "0d4aca83-af21-4d70-bdb9-82b05454d95f",
"buyerPaymentDocRef1": "Test1",
"buyerPaymentDocRef2": "Test2",
"buyerCode": "บริษัท ครี-ฟูล จำกัด",
"buyerTaxId": "0105541022877",
"reverseMessage": "Testing reverse"
}
```
#### Example Response
```json
{
"code": 200,
"message": "success",
"timestamp": "2021-03-04T09:46:04.426Z",
"data": {
"buyerReversalPaymentDocNumber": "0d4aca83-af21-4d70-bdb9-82b05454d95f,
"buyerReversalPaymentDocRef1": "Test1",
"buyerReversalPaymentDocRef2": "Test2"
}
}
```