Class: Square::GiftCards::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/gift_cards/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::GiftCards::Client



7
8
9
# File 'lib/square/gift_cards/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#activitiesSquare::Activities::Client

Returns:

  • (Square::Activities::Client)


150
151
152
# File 'lib/square/gift_cards/client.rb', line 150

def activities
  @activities ||= Square::GiftCards::Activities::Client.new(client: @client)
end

#create(request_options: {}, **params) ⇒ Square::Types::CreateGiftCardResponse

Creates a digital gift card or registers a physical (plastic) gift card. The resulting gift card has a ‘PENDING` state. To activate a gift card so that it can be redeemed for purchases, call [CreateGiftCardActivity](api-endpoint:GiftCardActivities-CreateGiftCardActivity) and create an `ACTIVATE` activity with the initial balance. Alternatively, you can use [RefundPayment](api-endpoint:Refunds-RefundPayment) to refund a payment to the new gift card.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/square/gift_cards/client.rb', line 41

def create(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/gift-cards",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::CreateGiftCardResponse.load(_response.body)
  end

  raise _response.body
end

#get(request_options: {}, **params) ⇒ Square::Types::GetGiftCardResponse

Retrieves a gift card using the gift card ID.



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/square/gift_cards/client.rb', line 135

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/gift-cards/#{params[:id]}"
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetGiftCardResponse.load(_response.body)
  end

  raise _response.body
end

#get_from_gan(request_options: {}, **params) ⇒ Square::Types::GetGiftCardFromGanResponse

Retrieves a gift card using the gift card account number (GAN).



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/square/gift_cards/client.rb', line 59

def get_from_gan(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/gift-cards/from-gan",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetGiftCardFromGanResponse.load(_response.body)
  end

  raise _response.body
end

#get_from_nonce(request_options: {}, **params) ⇒ Square::Types::GetGiftCardFromNonceResponse

Retrieves a gift card using a secure payment token that represents the gift card.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/square/gift_cards/client.rb', line 77

def get_from_nonce(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/gift-cards/from-nonce",
    body: params
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::GetGiftCardFromNonceResponse.load(_response.body)
  end

  raise _response.body
end

Links a customer to a gift card, which is also referred to as adding a card on file.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/square/gift_cards/client.rb', line 95

def link_customer(request_options: {}, **params)
  _path_param_names = ["gift_card_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/gift-cards/#{params[:gift_card_id]}/link-customer",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::LinkCustomerToGiftCardResponse.load(_response.body)
  end

  raise _response.body
end

#list(request_options: {}, **params) ⇒ Square::Types::ListGiftCardsResponse

Lists all gift cards. You can specify optional filters to retrieve a subset of the gift cards. Results are sorted by ‘created_at` in ascending order.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/square/gift_cards/client.rb', line 15

def list(request_options: {}, **params)
  _query_param_names = %w[type state limit cursor customer_id]
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "GET",
    path: "v2/gift-cards",
    query: _query
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::ListGiftCardsResponse.load(_response.body)
  end

  raise _response.body
end

Unlinks a customer from a gift card, which is also referred to as removing a card on file.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/square/gift_cards/client.rb', line 115

def unlink_customer(request_options: {}, **params)
  _path_param_names = ["gift_card_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::SANDBOX,
    method: "POST",
    path: "v2/gift-cards/#{params[:gift_card_id]}/unlink-customer",
    body: params.except(*_path_param_names)
  )
  _response = @client.send(_request)
  if _response.code >= "200" && _response.code < "300"
    return Square::Types::UnlinkCustomerFromGiftCardResponse.load(_response.body)
  end

  raise _response.body
end