Tổng đài hỗ trợ - 
1900 6750
( 7:00 - 22:00 )

Transaction

Transaction được tạo với mỗi Order khi có một giao dịch chuyển tiền.

Có 5 loại Transaction:

  • Authorization: Giao dịch xác thực khoản tiền thanh toán của khách hàng. Tiền chỉ đến tay chủ Shop khi giao dịch này được "Capture".
  • Sale: Giao dịch xác thực và nhận tiền diễn ra trong một bước.
  • Capture: Giao dịch nhận khoản tiền từ giao dịch xác thực
  • Void: Hủy một giao dịch "Authorization" hoặc "Capture" đang tạm hoãn.
  • Refund: Hoàn trả một phần hoặc toàn bộ khoản tiền đã nhận từ khách hàng. Giao dịch Refund chỉ diễn ra sau khi đã có giao dịch Capture.

Bạn có thể làm gì với Transaction?

Sapo API cho phép bạn thực hiện các thao tác sau với tài nguyên Transaction. Các phiên bản chi tiết hơn của những thao tác này có thể có:

Các thuộc tính của Transaction

amount
{ "amount" : "10.00" }

Số lượng tiền có trong Transaction.

authorization
{ "authorization" : "null" }

Mã xác thực ứng với Transaction.

created_on
{ "created_on" : "2012-03-13T16:09:54Z" }

Thời gian Transaction được tạo. API trả về kết quả theo định dạnh chuẩn ISO 8601.

device_id
{ "device_id" : "null" }

Số duy nhất định danh cho thiết bị.

gateway
{ "gateway" : "bogus" }

Tên của cổng thanh toán giao dịch được thực hiện thông qua nó.

source_name
{ "source_name" : "web" }

Nguồn thực hiện giao dịch. Giá trị này được thiết lập bởi Sapo và không thể ghi đè. Các giá trị có thể là: 'web', 'pos', 'iphone', 'android'

id
{ "id" : 999225661 }

Số duy nhất định danh Transaction.

kind
{ "kind" : "capture" }

Loại Transaction:

  • authorization: Giao dịch xác thực số tiền mà khách hàng đồng ý thanh toán. Khoảng thời gian xác thực kéo dài từ 7 đến 30 ngày (phụ thuộc vào dịch vụ thanh toán) trong lúc chủ Shop chờ nhận khoản tiền từ khách hàng.
  • capture: Giao dịch nhận tiền của Shop từ Authorization Transaction.
  • sale: Kết hợp của cả 2 loại authorization và capture Transaction.
  • void: Hủy các loại authorization hoặc capture Transaction ở trạng thái pending.
  • refund: Một phần hoặc tất cả số tiền đã nhận được hoàn trả cho khách hàng.
order_id
{ "order_id" : 450789469 }

Số duy nhất định danh đơn hàng.

receipt
{ "receipt" : {} }
  • testcase:
  • authorization:
error_code
{ "error_code" : "invalid_cvc" }

Mã lỗi được chuẩn hóa, không phụ thuộc vào loại hình thanh toán. Có thể có giá trị null.

  • incorrect_number
  • invalid_number
  • invalid_expiry_date
  • invalid_cvc
  • expired_card
  • incorrect_cvc
  • incorrect_zip
  • incorrect_address
  • card_declined
  • processing_error
  • call_issuer
  • pick_up_card
status
{ "status" : "success" }

Trạng thái của Transaction. Các giá trị hợp lệ là: pending, failure, success hoặc error.

test
{ "test" : true }

Giá trị tùy chọn cho Transaction với mục đích thử nghiệm. Các giá trị hợp lệ là "true" hoặc "false."

user_id
{ "user_id" : "null" }

Số duy nhất định danh người dùng.

currency
{ "currency" : "USD" }

Mã tiền tệ gồm 3 chữ cái (chuẩn ISO 4217).

Endpoints

GET/admin/orders/450789469/transactions.json
since_id

Giới hạn kết quả trả về sau một ID xác định

fields

danh sách các trường trong kết quả trả về, cách nhau bởi dấu phẩy

Lấy tất cả giao dịch tiền tệ của đơn hàng.

GET /admin/orders/#{id}/transactions.json
Xem kết quả
HTTP/1.1 200 OK
{
  "transactions": [
    {
      "id": 179259969,
      "order_id": 450789469,
      "amount": "209.00",
      "kind": "refund",
      "gateway": "bogus",
      "status": "success",
      "message": null,
      "created_on": "2005-08-05T12:59:12Z",
      "test": false,
      "authorization": "authorization-key",
      "currency": "USD",
      "location_id": null,
      "user_id": null,
      "parent_id": null,
      "device_id": null,
      "receipt": {},
      "error_code": null,
      "source_name": "web"
    },
    {
      "id": 389404469,
      "order_id": 450789469,
      "amount": "409.94",
      "kind": "authorization",
      "gateway": "bogus",
      "status": "success",
      "message": null,
      "created_on": "2005-08-01T11:57:11Z",
      "test": false,
      "authorization": "authorization-key",
      "currency": "USD",
      "location_id": null,
      "user_id": null,
      "parent_id": null,
      "device_id": null,
      "receipt": {
        "testcase": true,
        "authorization": "123456"
      },
      "error_code": null,
      "source_name": "web",
      "payment_details": {
        "credit_card_bin": null,
        "avs_result_code": null,
        "cvv_result_code": null,
        "credit_card_number": "•••• •••• •••• 4242",
        "credit_card_company": "Visa"
      }
    },
    {
      "id": 801038806,
      "order_id": 450789469,
      "amount": "250.94",
      "kind": "capture",
      "gateway": "bogus",
      "status": "success",
      "message": null,
      "created_on": "2005-08-05T10:22:51Z",
      "test": false,
      "authorization": "authorization-key",
      "currency": "USD",
      "location_id": null,
      "user_id": null,
      "parent_id": null,
      "device_id": null,
      "receipt": {},
      "error_code": null,
      "source_name": "web"
    }
  ]
}

Lấy tất cả các giao dịch tiền của đơn hàng sau một ID xác định

GET /admin/orders/#{id}/transactions.json?since_id=801038806
Xem kết quả
HTTP/1.1 200 OK
{
  "transactions": [
    {
      "id": 1068278478,
      "order_id": 450789469,
      "amount": "10.00",
      "kind": "capture",
      "gateway": "bogus",
      "status": "success",
      "message": "Bogus Gateway: Forced success",
      "created_on": "2015-12-08T11:40:43Z",
      "test": true,
      "authorization": null,
      "currency": "USD",
      "location_id": null,
      "user_id": null,
      "parent_id": 389404469,
      "device_id": null,
      "receipt": {},
      "error_code": null,
      "source_name": "755357713"
    }
  ]
}
GET/admin/orders/450789469/transactions/count.json

Tổng số tất cả giao dịch.

GET /admin/orders/#{id}/transactions/count.json
Xem kết quả
HTTP/1.1 200 OK
{
  "count": 3
}
GET/admin/orders/450789469/transactions/389404469.json
fields

danh sách các trường trong kết quả trả về, cách nhau bởi dấu phẩy

Lấy một Transaction.

GET /admin/orders/#{id}/transactions/#{id}.json
Xem kết quả
HTTP/1.1 200 OK
{
  "transaction": {
    "id": 389404469,
    "order_id": 450789469,
    "amount": "409.94",
    "kind": "authorization",
    "gateway": "bogus",
    "status": "success",
    "message": null,
    "created_on": "2005-08-01T11:57:11Z",
    "test": false,
    "authorization": "authorization-key",
    "currency": "USD",
    "location_id": null,
    "user_id": null,
    "parent_id": null,
    "device_id": null,
    "receipt": {
      "testcase": true,
      "authorization": "123456"
    },
    "error_code": null,
    "source_name": "web",
    "payment_details": {
      "credit_card_bin": null,
      "avs_result_code": null,
      "cvv_result_code": null,
      "credit_card_number": "•••• •••• •••• 4242",
      "credit_card_company": "Visa"
    }
  }
}
POST/admin/orders/450789469/transactions.json

Tạo một giao dịch hoàn trả một phần

POST /admin/orders/#{id}/transactions.json
{
  "transaction": {
    "kind": "refund",
    "amount": "5.00"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "transaction": {
    "id": 1068278475,
    "order_id": 450789469,
    "amount": "5.00",
    "kind": "refund",
    "gateway": "bogus",
    "status": "success",
    "message": "Bogus Gateway: Forced success",
    "created_on": "2015-12-08T11:40:41Z",
    "test": true,
    "authorization": null,
    "currency": "USD",
    "location_id": null,
    "user_id": null,
    "parent_id": 1068278474,
    "device_id": null,
    "receipt": {},
    "error_code": null,
    "source_name": "755357713"
  }
}

Nhận một số lượng tiền ứng với một giao dịch authorization trước đó.

POST /admin/orders/#{id}/transactions.json
{
  "transaction": {
    "amount": "10.00",
    "kind": "capture"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "transaction": {
    "id": 1068278476,
    "order_id": 450789469,
    "amount": "10.00",
    "kind": "capture",
    "gateway": "bogus",
    "status": "success",
    "message": "Bogus Gateway: Forced success",
    "created_on": "2015-12-08T11:40:41Z",
    "test": true,
    "authorization": null,
    "currency": "USD",
    "location_id": null,
    "user_id": null,
    "parent_id": 389404469,
    "device_id": null,
    "receipt": {},
    "error_code": null,
    "source_name": "755357713"
  }
}

Nhận toàn bộ số tiền ứng với giao dịch Authorization trước đó

POST /admin/orders/#{id}/transactions.json
{
  "transaction": {
    "kind": "capture"
  }
}
Xem kết quả
HTTP/1.1 201 Created
{
  "transaction": {
    "id": 1068278477,
    "order_id": 450789469,
    "amount": "409.94",
    "kind": "capture",
    "gateway": "bogus",
    "status": "success",
    "message": "Bogus Gateway: Forced success",
    "created_on": "2015-12-08T11:40:41Z",
    "test": true,
    "authorization": null,
    "currency": "USD",
    "location_id": null,
    "user_id": null,
    "parent_id": 389404469,
    "device_id": null,
    "receipt": {},
    "error_code": null,
    "source_name": "755357713"
  }
}

Bài viết trên có hữu ích cho bạn không?

Hữu ích Không hữu ích
Số lượt đánh giá hữu ích: