跳到主要內容

付款連結

付款連結是一個可分享、可重複使用的頁面,用於銷售產品或服務。您可以為一組特定的產品和價格建立一個連結,並透過各種管道與多個客戶分享。這樣無需建立完整的結帳流程,即可快速輕鬆地收款。

付款連結物件

付款連結物件包含向客戶展示付款頁面所需的所有資訊。以下是其一些關鍵屬性:

AttributeTypeDescription
idstring付款連結物件的唯一識別碼。
urlstring付款頁面的 URL。客戶可以被重新導向到此 URL 進行付款。
activeboolean付款連結目前是否有效且可用於付款。
line_itemsarray將要購買的產品和價格列表。
after_completionobject購買完成後的行為,例如重新導向到一個 URL 或顯示確認訊息。
allow_promotion_codesboolean啟用在付款頁面上使用促銷代碼。
currency_idstring三字母 ISO 貨幣代碼。
metadataobject一組可以附加到物件上的鍵值對。可用於儲存額外資訊。
created_atstring物件建立時的時間戳。

建立付款連結

建立一個新的付款連結。

建立付款連結

javascript
const paymentLink = await payment.paymentLinks.create({
  line_items: [
    {
      price_id: 'price_xxxxxxxxxxxxxx',
      quantity: 1,
      adjustable_quantity: {
        enabled: true,
        minimum: 1,
        maximum: 10,
      },
    },
  ],
  after_completion: {
    type: 'hosted_confirmation',
    hosted_confirmation: {
      custom_message: 'Thanks for your purchase!',
    },
  },
  metadata: {
    order_id: '6735',
  },
});

參數

NameTypeDescription
line_itemsarray必填。 訂單項目物件的列表,每個物件代表要購買的產品。詳情見下文。
namestring付款連結的可選內部名稱。
lookup_keystring一個可選的唯一字串,可用於擷取付款連結。
currency_idstring此付款連結的貨幣 ID。如果未提供,則使用預設貨幣。
after_completionobject指定成功付款後的行為。詳情見下文。
allow_promotion_codesboolean設定為 true 以允許兌換促銷代碼。預設為 false
consent_collectionobject設定促銷和服務條款的同意收集。詳情見下文。
nft_mint_settingsobject付款完成後鑄造 NFT 的設定。詳情見下文。
metadataobject一組用於儲存額外資訊的鍵值對。

line_items 物件屬性

NameTypeDescription
price_idstring必填。 價格物件的 ID。
quantitynumber必填。 正在購買的產品數量。必須至少為 1。
adjustable_quantityobject允許客戶在付款頁面上調整此訂單項目數量的設定。詳情見下文。

line_items.adjustable_quantity 物件屬性

NameTypeDescription
enabledboolean必填。 設定為 true 以允許數量調整。
minimumnumber客戶可選擇的最小數量。必須為 0 或更大。
maximumnumber客戶可選擇的最大數量。必須大於 minimum

after_completion 物件屬性

NameTypeDescription
typestring必填。 完成行為的類型。可以是 hosted_confirmationredirect
hosted_confirmationobject向客戶顯示一個託管的確認訊息。當 typehosted_confirmation 時使用。
redirectobject將客戶重新導向到指定的 URL。當 typeredirect 時使用。

after_completion.hosted_confirmation 物件屬性

NameTypeDescription
custom_messagestring一個可選的自訂訊息,顯示給客戶。最多 200 個字元。

after_completion.redirect 物件屬性

NameTypeDescription
urlstring要將客戶重新導向的 URL。最多 2048 個字元。

consent_collection 物件屬性

NameTypeDescription
promotionsstring決定如何處理促銷通訊的同意。可以是 noneopt_inopt_out
terms_of_servicestring決定如何處理服務條款的同意。可以是 noneopt_inopt_out

nft_mint_settings 物件屬性

NameTypeDescription
enabledboolean必填。 設定為 true 以在付款後啟用 NFT 鑄造。
factorystring用於鑄造 NFT 的工廠地址。如果 enabledtrue,則為必填。

返回值

如果建立成功,則返回一個 TPaymentLinkExpanded 物件。

回應

json
{
  "id": "plink_xxxxxxxxxxxxxx",
  "active": true,
  "url": "https://payment.arcblock.io/pl/plink_xxxxxxxxxxxxxx",
  "line_items": [
    {
      "price_id": "price_xxxxxxxxxxxxxx",
      "quantity": 1,
      "adjustable_quantity": {
        "enabled": true,
        "minimum": 1,
        "maximum": 10
      }
    }
  ],
  "after_completion": {
    "type": "hosted_confirmation",
    "hosted_confirmation": {
      "custom_message": "Thanks for your purchase!"
    }
  },
  "metadata": {
    "order_id": "6735"
  }
}

擷取付款連結

擷取現有付款連結的詳細資訊。

擷取付款連結

javascript
const paymentLinkId = 'plink_xxxxxxxxxxxxxx';
const paymentLink = await payment.paymentLinks.retrieve(paymentLinkId);

參數

NameTypeDescription
idstring必填。 要擷取的付款連結的唯一識別碼或 lookup_key

返回值

返回一個 TPaymentLinkExpanded 物件,其中包含有關訂單項目及其相關價格和產品的擴充詳細資訊。

回應

json
{
  "id": "plink_xxxxxxxxxxxxxx",
  "active": true,
  "url": "https://payment.arcblock.io/pl/plink_xxxxxxxxxxxxxx",
  "line_items": [
    {
      "price_id": "price_xxxxxxxxxxxxxx",
      "quantity": 1,
      "price": {
        "id": "price_xxxxxxxxxxxxxx",
        "product_id": "prod_yyyyyyyyyyyyyy",
        "unit_amount": "10.00",
        "product": {
          "id": "prod_yyyyyyyyyyyyyy",
          "name": "My Awesome Product"
        }
      }
    }
  ]
}

更新付款連結

透過設定傳入參數的值來更新付款連結。任何未提供的參數將保持不變。請注意,您無法更新已封存的付款連結。

更新付款連結

javascript
const paymentLinkId = 'plink_xxxxxxxxxxxxxx';
const updatedPaymentLink = await payment.paymentLinks.update(paymentLinkId, {
  active: false,
  metadata: {
    order_id: '6735-updated'
  }
});

參數

NameTypeDescription
idstring必填。 要更新的付款連結的 ID。
...第二個參數是一個包含要更新欄位的物件。它支援許多與建立方法相同的參數,例如 activeline_itemsmetadataafter_completion。所有欄位都是可選的。

返回值

返回更新後的 TPaymentLink 物件。

回應

json
{
  "id": "plink_xxxxxxxxxxxxxx",
  "active": false,
  "metadata": {
    "order_id": "6735-updated"
  }
}

列出所有付款連結

返回您的付款連結列表。

列出付款連結

javascript
const paymentLinks = await payment.paymentLinks.list({
  active: true,
  limit: 5
});

參數

NameTypeDescription
activeboolean篩選列表,僅包含有效或無效的付款連結。
donationstring設定為 'hide' 以排除 submit_typedonate 的付款連結。
pagenumber分頁的頁碼。預設為 1
pageSizenumber每頁返回的物件數量。預設為 20
orderstring對結果進行排序的順序。例如,'created_at:DESC'

返回值

返回一個分頁物件,其中包含一個 TPaymentLinkExpanded 物件的 list

回應

json
{
  "count": 15,
  "list": [
    {
      "id": "plink_xxxxxxxxxxxxxx",
      "active": true
    },
    {
      "id": "plink_yyyyyyyyyyyyyy",
      "active": true
    }
  ],
  "paging": {
    "page": 1,
    "pageSize": 5
  }
}

封存付款連結

停用付款連結,使其無法用於付款。此操作是可逆的,可以透過將 active 屬性更新為 true 來還原。

封存付款連結

javascript
const paymentLinkId = 'plink_xxxxxxxxxxxxxx';
const archivedPaymentLink = await payment.paymentLinks.archive(paymentLinkId);

參數

NameTypeDescription
idstring必填。 要封存的付款連結的 ID。

返回值

返回已封存的 TPaymentLink 物件,其 active 屬性設定為 false

回應

json
{
  "id": "plink_xxxxxxxxxxxxxx",
  "active": false,
  "url": "https://payment.arcblock.io/pl/plink_xxxxxxxxxxxxxx"
}