通过Shopify API接受付款

时间:2012-08-22 16:25:29

标签: shopify

在Shopify管理区域中,每个订单上都有一个“接受付款”按钮。是否有可以通过API执行的等效操作?

2 个答案:

答案 0 :(得分:3)

是。您可以创建交易并捕获先前授权的金额。

 ShopifyAPI::Transaction.create({:order_id => order.id, :kind => 'capture'})

答案 1 :(得分:1)

是的,确保原始订单是通过API创建的,状态为“待定”,交易类型为“授权”,交易状态为“成功”。然后,当您捕获付款时,它只会改变财务状况。您不能只是在不捕获交易的情况下更改订单上的财务状况值。

因此,这是使用API​​创建订单的原始请求:

POST /admin/orders.json

extension Order: Migration {
    static func prepare(on connection: PostgreSQLConnection) -> Future<Void> {
        return Database.create(self, on: connection) { builder in
            try addProperties(to: builder)
            try builder.addReference(from: \.stationID, to: \Station.id)

            builder.schema.addFields = builder.schema.addFields.map {
                guard $0.type.type == .timestamp else { return $0 }

                let defaultValue = $0.name == CodingKeys.created.rawValue ? "now()" : nil
                let type = PostgreSQLColumn(type: .date, default: defaultValue)

                return SchemaField<PostgreSQLDatabase>(name: $0.name, type: type, isOptional: $0.isOptional)
            }
        }
    }
}

然后捕获事务执行此操作:

POST /admin/orders/{order_id}/transactions.json

{
   "financial_status": "pending",
   "fulfillment_status": "fulfilled",
   "transactions": [{
      "amount": "21",
      "kind": "authorization",
      "gateway": "Gateway",
      "status": "success",
      "source_name": "My API"
   }]
}

确保您为API上的订单启用了写入权限: https://redeeem.myshopify.com/admin/apps/private