Class: Square::Checkout::PaymentLinks::Client
- Inherits:
-
Object
- Object
- Square::Checkout::PaymentLinks::Client
- Defined in:
- lib/square/checkout/payment_links/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreatePaymentLinkResponse
Creates a Square-hosted checkout page.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeletePaymentLinkResponse
Deletes a payment link.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetPaymentLinkResponse
Retrieves a payment link.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListPaymentLinksResponse
Lists all payment links.
-
#update(request_options: {}, **params) ⇒ Square::Types::UpdatePaymentLinkResponse
Updates a payment link.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/checkout/payment_links/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreatePaymentLinkResponse
Creates a Square-hosted checkout page. Applications can share the resulting payment link with their buyer to pay for goods and services.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/square/checkout/payment_links/client.rb', line 75 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/online-checkout/payment-links", body: Square::Checkout::PaymentLinks::Types::CreatePaymentLinkRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CreatePaymentLinkResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Square::Types::DeletePaymentLinkResponse
Deletes a payment link.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/square/checkout/payment_links/client.rb', line 185 def delete(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/online-checkout/payment-links/#{params[:id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::DeletePaymentLinkResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::GetPaymentLinkResponse
Retrieves a payment link.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/square/checkout/payment_links/client.rb', line 110 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/online-checkout/payment-links/#{params[:id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::GetPaymentLinkResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Square::Types::ListPaymentLinksResponse
Lists all payment links.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/square/checkout/payment_links/client.rb', line 27 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[cursor limit] query_params = {} query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["limit"] = params[:limit] if params.key?(:limit) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :payment_links, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/online-checkout/payment-links", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::ListPaymentLinksResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#update(request_options: {}, **params) ⇒ Square::Types::UpdatePaymentLinkResponse
Updates a payment link. You can update the ‘payment_link` fields such as `description`, `checkout_options`, and `pre_populated_data`. You cannot update other fields such as the `order_id`, `version`, `URL`, or `timestamp` field.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/square/checkout/payment_links/client.rb', line 146 def update(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Checkout::PaymentLinks::Types::UpdatePaymentLinkRequest.new(params).to_h non_body_param_names = ["id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/online-checkout/payment-links/#{params[:id]}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::UpdatePaymentLinkResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |