2co-client 中文文档教程

发布于 6年前 浏览 23 项目主页 更新于 3年前

未维护:(2018-11-22) 2co 最近更改了他们的 API,新 API 非常不同且内容广泛。 API 中的大部分东西我都不需要,所以为他们的 API 维护一个 SDK 对我来说没有意义。 虽然此处的代码目前有效,但 API 本身仅部分有效,预计 API 很快就会停产。

2co-client

用于 2checkout API 的瘦 node.js 客户端。

在生产使用中,在 Errorception 运行支付系统。

Installation

$ npm install 2co-client

Usage

var client = require("2co-client")(options);

client.sales.list(function(err, salesInformation) {
    // As you'd expect  
});

Initialization

var client = require("2co-client")(options);

options 是一个可以包含以下属性的对象:

  • username Your 2checkout API user's username
  • password Your 2checkout API user's password
  • secret Your 2checkout secret
  • logFile (optional) The path to a file that this module should output logs to. Requests and responses are logged here.
  • test Enables demo mode. Bypasses INS and return data checks, and makes them always return true.

Methods

客户端提供的方法反映了 2co 高级用户指南 [PDF]。 使用此模块时,随身携带一份用户指南会很有帮助。

所有方法都将回调作为最后一个参数,采用典型的 node.js 风格。 一些方法可能有一个可选的第一个参数,它应该是一个对象。 此对象用作要发送到 API 的有效负载。

如果网络层出现问题,错误将是一个 JS 异常对象,或者如果 API 返回 400/500 系列错误,则错误将是一个对象数组。

API 方法列表如下。

client.account

  • client.account.companyInfo: Retrieves your account's company information details. GETs /acct/detail_company_info.
  • client.account.contactInfo: Retrieve your account's contact information details. GETs /acct/detail_contact_info.
  • client.account.pendingPayment: Get a detailed estimate of the current pending payment. GETs /acct/detail_pending_payment.
  • client.account.listPayments: Get a list of past payments. GETs /acct/list_payments.

client.sales

  • client.sales.details:检索有关特定销售或发票的信息。 获取 /sales/detail_sale

  • client.sales.list:检索所有销售的摘要或仅检索与各种销售属性匹配的销售的摘要。 获取 /sales/list_sales

  • client.sales.refundInvoice:尝试对发票进行全额或部分退款。 POST 到 /sales/refund_invoice

  • client.sales.refundLineitem:尝试对发票进行全额或部分退款。 POST 到 /sales/refund_lineitem

  • client.sales.stopLineitemRecurring:尝试停止指定销售的重复订单项。 POST 到 /sales/refund_lineitem_recurring

  • client.sales.markShipped:尝试将订单标记为已发货,如果在调用中指定,将尝试重新授权销售。 POST 到 /sales/mark_shipped

  • client.sales.createComment:为指定的销售添加评论。 发布到 /sales/create_comment

client.products

  • client.products.details:检索单个产品的详细信息。 GETs /products/detail_product

  • client.products.list:检索帐户中所有产品的列表。 GETs /products/list_products

  • client.products.create:创建一个新产品。 POST 到 /products/create_product

  • client.products.update:更新产品。 POST 到 /products/update_product

  • client.products.del:删除一个产品。 POST 到 /products/delete_product

  • client.products.options.details:检索单个选项的详细信息。 GETs /products/detail_options

  • client.products.options.list:检索帐户中所有选项的列表。 GETs /products/list_products

  • client.products.options.create:创建一个新的产品选项。 POST 到 /products/create_option

  • client.products.options.update:更新产品选项。 POST 到 /products/update_option

  • client.products.options.del:删除产品选项。 POST 到 /products/delete_option

  • client.products.coupons.details:检索单个优惠券的详细信息。 获取 /products/detail_coupon

  • client.products.coupons.list:检索帐户中所有优惠券的列表。 获取 /products/list_coupons

  • client.products.coupons.create:创建新优惠券。 POST 到 /products/create_coupon

  • client.products.coupons.update:更新优惠券。 POST 到 /products/update_coupon

  • client.products.coupons.del:删除优惠券。 POST 到 /products/delete_coupon

Additional methods

以下方法简化了使用 API 的一些琐事。

client.canTrustINS

检查2checkout返回的INS数据是否有效且未被篡改。 您必须在创建客户端时传递 options.secret 才能正常工作。 如果 options.test 为真,将始终返回真。 您必须将收到的 HTTP POST 正文作为键值对的 JSON 对象传递给它。 如果您将 Express 与 bodyParser 一起使用,则 req.body 已按预期包含对象。

client.canTrustReturnData

通过 2checkout 检查购买流程的退货数据是否有效。 您必须在创建客户端时传递 options.secret 才能正常工作。 如果 options.test 为真,将始终返回真。 您必须将查询字符串作为键值对的 JSON 对象传递给它。 如果您使用的是 Express,则 req.query 已包含预期的对象。

License

麻省理工学院

Unmaintained: (2018-11-22) 2co has recently changed their API, and the new API is very different and vast. I don't need most of the things in the API, so it doesn't make sense for me to maintain a SDK for their API. While the code here works as of today, the API itself only works partially, and expect the API to be EOL'd soon.

2co-client

A thin node.js client for the 2checkout API.

In production use, running the payment system at Errorception.

Installation

$ npm install 2co-client

Usage

var client = require("2co-client")(options);

client.sales.list(function(err, salesInformation) {
    // As you'd expect  
});

Initialization

var client = require("2co-client")(options);

options is an object that can contain the following properties:

  • username Your 2checkout API user's username
  • password Your 2checkout API user's password
  • secret Your 2checkout secret
  • logFile (optional) The path to a file that this module should output logs to. Requests and responses are logged here.
  • test Enables demo mode. Bypasses INS and return data checks, and makes them always return true.

Methods

The methods provided by the client mirror the API endpoints as specified in the 2co Advanced User Guide [PDF]. It will be helpful to keep a copy of the user guide handy when using this module.

All methods take a callback as the last argument, in the typical node.js style. Some methods might take an optional first argument, which is expected to be an object. This object is used as the payload to be sent to the API.

Errors will either be a JS Exception object if there was a problem with the network layer, or will be an array of objects if the API returned a 400/500 series error.

A listing of API methods follows.

client.account

  • client.account.companyInfo: Retrieves your account's company information details. GETs /acct/detail_company_info.
  • client.account.contactInfo: Retrieve your account's contact information details. GETs /acct/detail_contact_info.
  • client.account.pendingPayment: Get a detailed estimate of the current pending payment. GETs /acct/detail_pending_payment.
  • client.account.listPayments: Get a list of past payments. GETs /acct/list_payments.

client.sales

  • client.sales.details: Retrieve information about a specific sale or invoice. GETs /sales/detail_sale.

  • client.sales.list: Retrieve a summary of all sales or only those matching a variety of sale attributes. GETs /sales/list_sales.

  • client.sales.refundInvoice: Attempts to issue a full or partial refund on an invoice. POSTs to /sales/refund_invoice.

  • client.sales.refundLineitem: Attempt to issue a full or partial refund on an invoice. POSTs to /sales/refund_lineitem.

  • client.sales.stopLineitemRecurring: Attempt to stop a recurring line item for a specified sale. POSTs to /sales/refund_lineitem_recurring.

  • client.sales.markShipped: Attempt to mark an order as shipped and will attempt to reauthorize sale if specified in call. POSTs to /sales/mark_shipped.

  • client.sales.createComment: Add a comment to a specified sale. POSTs to /sales/create_comment.

client.products

  • client.products.details: Retrieve the details for a single product. GETs /products/detail_product.

  • client.products.list: Retrieve list of all products in account. GETs /products/list_products.

  • client.products.create: Create a new product. POSTs to /products/create_product.

  • client.products.update: Update a product. POSTs to /products/update_product.

  • client.products.del: Deletes a product. POSTs to /products/delete_product.

  • client.products.options.details: Retrieve the details for a single option. GETs /products/detail_options.

  • client.products.options.list: Retrieve list of all options in account. GETs /products/list_products.

  • client.products.options.create: Create a new product option. POSTs to /products/create_option.

  • client.products.options.update: Updates a product option. POSTs to /products/update_option.

  • client.products.options.del: Deletes a product option. POSTs to /products/delete_option.

  • client.products.coupons.details: Retrieve the details for a single coupon. GETs /products/detail_coupon.

  • client.products.coupons.list: Retrieve list of all coupons in the account. GETs /products/list_coupons.

  • client.products.coupons.create: Creates a new coupon. POSTs to /products/create_coupon.

  • client.products.coupons.update: Updates a coupon. POSTs to /products/update_coupon.

  • client.products.coupons.del: Deletes a coupon. POSTs to /products/delete_coupon.

Additional methods

The following methods simplify some of the chores of working with the API.

client.canTrustINS

Checks if the INS data returned by 2checkout is valid and not tampered with. You must pass options.secret when creating the client for this to work correctly. Will always return true if options.test is true. You must pass it the body of the HTTP POST you received, as a JSON object of key-value pairs. If you are using Express along with the bodyParser, the req.body already contains object as expected.

client.canTrustReturnData

Checks if the return data from the purchase process by 2checkout is valid. You must pass options.secret when creating the client for this to work correctly. Will always return true if options.test is true. You must pass it the query string as a JSON object of key-value pairs. If you are using Express, the req.query already contains the object as expected.

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文