Class: Zspay::Sale

Inherits:
Resource show all
Defined in:
lib/zspay/resources/sale.rb

Overview

The Sale class manages sale-related actions within the Zspay platform. It provides methods to create a sale, retrieve sale details, and refund a sale, extending the functionality from Zspay::Resource.

Class Method Summary collapse

Methods inherited from Resource

delete, endpoint, get, headers, parse_body, parse_json, patch, post, put, req, req_form, req_json, success_request?

Class Method Details

.create(sale, custom_token = nil) ⇒ OpenStruct

Creates a new sale on the Zspay platform.

Parameters:

  • sale (Hash)

    A hash containing the sale information.

  • custom_token (String, nil) (defaults to: nil)

    An optional custom token to use for the request.

Returns:

  • (OpenStruct)

    A structure containing the newly created sale’s details if the request is successful.



14
15
16
# File 'lib/zspay/resources/sale.rb', line 14

def create(sale, custom_token = nil)
  post("/vendas", sale, custom_token)
end

.refund(sale_id, custom_token = nil) ⇒ OpenStruct

Processes a refund for a specific sale.

This method sends a request to refund a previously made sale. The sale is identified by its unique ID.

Parameters:

  • sale_id (String)

    The unique identifier of the sale to refund.

  • custom_token (String, nil) (defaults to: nil)

    An optional custom token to use for the request.

Returns:

  • (OpenStruct)

    A structure indicating the result of the refund operation if the request is successful.



34
35
36
# File 'lib/zspay/resources/sale.rb', line 34

def refund(sale_id, custom_token = nil)
  post("/vendas/#{sale_id}/estornar", {}, custom_token)
end

.show(sale_id, custom_token = nil) ⇒ OpenStruct

Retrieves details of a specific sale.

Parameters:

  • sale_id (String)

    The unique identifier of the sale to retrieve.

  • custom_token (String, nil) (defaults to: nil)

    An optional custom token to use for the request.

Returns:

  • (OpenStruct)

    A structure containing the sale’s details if the request is successful.



23
24
25
# File 'lib/zspay/resources/sale.rb', line 23

def show(sale_id, custom_token = nil)
  get("/vendas/#{sale_id}", custom_token)
end