types.go (4036B)
1 package backend 2 3 // Timestamp is the JSON representation used by the Merchant API for an 4 // absolute point in time. 5 type Timestamp struct { 6 Seconds int64 `json:"t_s"` 7 } 8 9 // RelativeTime is the JSON representation used by the Merchant API for a 10 // duration. 11 type RelativeTime struct { 12 Microseconds int64 `json:"d_us"` 13 } 14 15 // OrderExtra is the application-owned portion of an order's contract terms. 16 // The demos use one set of fields for essays and another for donations. 17 type OrderExtra struct { 18 ArticleName string `json:"article_name,omitempty"` 19 Donor string `json:"donor,omitempty"` 20 Receiver string `json:"receiver,omitempty"` 21 Amount string `json:"amount,omitempty"` 22 } 23 24 // OrderInput describes an input required by an order choice. 25 type OrderInput struct { 26 Type string `json:"type"` 27 TokenFamilySlug string `json:"token_family_slug,omitempty"` 28 } 29 30 // OrderOutput describes an output produced by an order choice. 31 type OrderOutput struct { 32 Type string `json:"type"` 33 TokenFamilySlug string `json:"token_family_slug,omitempty"` 34 Amount string `json:"amount,omitempty"` 35 } 36 37 // OrderChoice is one payment alternative in a version 1 order. 38 type OrderChoice struct { 39 Amount string `json:"amount"` 40 Description string `json:"description,omitempty"` 41 Inputs []OrderInput `json:"inputs,omitempty"` 42 Outputs []OrderOutput `json:"outputs,omitempty"` 43 } 44 45 // Order contains the Merchant order fields used by the demo applications. 46 type Order struct { 47 Version int `json:"version,omitempty"` 48 Amount string `json:"amount,omitempty"` 49 Choices []OrderChoice `json:"choices,omitempty"` 50 Extra OrderExtra `json:"extra"` 51 FulfillmentURL string `json:"fulfillment_url"` 52 PublicReorderURL string `json:"public_reorder_url,omitempty"` 53 Summary string `json:"summary"` 54 PayDeadline Timestamp `json:"pay_deadline"` 55 WireTransferDeadline Timestamp `json:"wire_transfer_deadline"` 56 MinimumAge int `json:"minimum_age,omitempty"` 57 } 58 59 // PostOrderRequest is the request body for POST private/orders. 60 type PostOrderRequest struct { 61 Order Order `json:"order"` 62 RefundDelay RelativeTime `json:"refund_delay"` 63 SessionID string `json:"session_id,omitempty"` 64 CreateToken bool `json:"create_token,omitempty"` 65 } 66 67 // PostOrderResponse is the subset of the order creation response used by the 68 // demos. 69 type PostOrderResponse struct { 70 OrderID string `json:"order_id"` 71 Token string `json:"token,omitempty"` 72 } 73 74 // ContractTerms is the subset of contract terms read by the demos. 75 type ContractTerms struct { 76 Version int `json:"version,omitempty"` 77 Amount string `json:"amount,omitempty"` 78 Choices []OrderChoice `json:"choices,omitempty"` 79 Extra OrderExtra `json:"extra"` 80 RefundDeadline Timestamp `json:"refund_deadline"` 81 } 82 83 // OrderStatusResponse combines the fields used by the demos from the paid, 84 // claimed, and unpaid Merchant order status variants. 85 type OrderStatusResponse struct { 86 OrderStatus string `json:"order_status"` 87 Refunded bool `json:"refunded"` 88 ContractTerms ContractTerms `json:"contract_terms"` 89 ChoiceIndex *int `json:"choice_index,omitempty"` 90 AlreadyPaidOrderID string `json:"already_paid_order_id,omitempty"` 91 OrderStatusURL string `json:"order_status_url,omitempty"` 92 } 93 94 // OrderHistory is returned by GET private/orders. 95 type OrderHistory struct { 96 Orders []OrderHistoryEntry `json:"orders"` 97 } 98 99 // OrderHistoryEntry contains the fields used to locate an earlier payment in 100 // the same browser session. 101 type OrderHistoryEntry struct { 102 OrderID string `json:"order_id"` 103 Paid bool `json:"paid"` 104 } 105 106 // RefundRequest is the request body for an order refund. 107 type RefundRequest struct { 108 Refund string `json:"refund"` 109 Reason string `json:"reason"` 110 }