Class: BeyondApi::PaymentMethods

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/beyond_api/resources/payment_methods.rb

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods included from Utils

#file_content_type, #handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BeyondApi::Base

Instance Method Details

#activate(payment_method_id) ⇒ Object

A POST request is used to activate a payment method.

$ curl 'https://api-shop.beyondshop.cloud/api/payment-methods/da313b73-ea6b-49c7-8a3d-d707934098b8/activate' -i -X POST \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.payment_methods.activate("da313b73-ea6b-49c7-8a3d-d707934098b8")

Parameters:

  • payment_method_id (String)

    the payment method UUID

Returns:

  • true

Scopes:

  • pymt:u



25
26
27
28
29
# File 'lib/beyond_api/resources/payment_methods.rb', line 25

def activate(payment_method_id)
  response, status = BeyondApi::Request.post(@session, "/payment-methods/#{payment_method_id}/activate")

  handle_response(response, status, respond_with_true: true)
end

#all(params = {}) ⇒ OpenStruct

A GET request is used to list all payment methods in a paged way.

$ curl 'https://api-shop.beyondshop.cloud/api/payment-methods' -i -X GET \
    -H 'Content-Type: application/hal+json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@payment_methods = session.payment_methods.all(size: 100, page: 0)

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :paginated (Boolean)
  • :size (Integer)

    the page size

  • :page (Integer)

    the page number

Returns:

  • (OpenStruct)

Scopes:

  • pymt:r



50
51
52
# File 'lib/beyond_api/resources/payment_methods.rb', line 50

def all(params = {})
  handle_all_request("/payment-methods", :payment_methods, params)
end

#deactivate(payment_method_id) ⇒ Object

A POST request is used to deactivate a payment method.

$ curl 'https://api-shop.beyondshop.cloud/api/payment-methods/157f930f-328a-4d7a-974d-66bc3b4dd28e/deactivate' -i -X POST \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

session.payment_methods.deactivate("157f930f-328a-4d7a-974d-66bc3b4dd28e")

Parameters:

  • payment_method_id (String)

    the payment method UUID

Returns:

  • true

Scopes:

  • pymt:u



70
71
72
73
74
# File 'lib/beyond_api/resources/payment_methods.rb', line 70

def deactivate(payment_method_id)
  response, status = BeyondApi::Request.post(@session, "/payment-methods/#{payment_method_id}/deactivate")

  handle_response(response, status, respond_with_true: true)
end

#find(payment_method_id) ⇒ OpenStruct

A GET request is used to retrieve the details of a payment method.

$ curl 'https://api-shop.beyondshop.cloud/api/payment-methods/7d964402-8f67-48f3-af86-6c35abe4fa08' -i -X GET \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>'

Examples:

@payment_method = session.payment_methods.find("7d964402-8f67-48f3-af86-6c35abe4fa08")

Parameters:

  • payment_method_id (String)

    the payment method UUID

Returns:

  • (OpenStruct)

Scopes:

  • pymt:r



93
94
95
96
97
# File 'lib/beyond_api/resources/payment_methods.rb', line 93

def find(payment_method_id)
  response, status = BeyondApi::Request.get(@session, "/payment-methods/#{payment_method_id}")

  handle_response(response, status)
end

#sort(payment_method_ids) ⇒ OpenStruct

A PUT request is used to sort payment methods.

$ curl 'https://api-shop.beyondshop.cloud/api/payment-methods' -i -X PUT \
    -H 'Content-Type: text/uri-list' \
    -H 'Authorization: Bearer <Access token>' \
    -d 'https://api-shop.beyondshop.cloud/api/payment-methods/dd59a52b-0661-49f9-82c3-e063ff80328f
        https://api-shop.beyondshop.cloud/api/payment-methods/66b22fb2-2184-4ea1-9143-44ae1d230d49
        https://api-shop.beyondshop.cloud/api/payment-methods/a9462eae-ed72-4e29-b853-f04537c8ab11
        https://api-shop.beyondshop.cloud/api/payment-methods/84172da4-5baa-4a99-b779-33d673bed6d1'

Examples:

payment_method_ids = [
  "dd59a52b-0661-49f9-82c3-e063ff80328f",
  "66b22fb2-2184-4ea1-9143-44ae1d230d49",
  "a9462eae-ed72-4e29-b853-f04537c8ab11",
  "84172da4-5baa-4a99-b779-33d673bed6d1"
]

session.payment_methods.sort(payment_method_ids)

Parameters:

  • payment_method_ids (Array)

    the payment method UUIDs

Returns:

  • (OpenStruct)

Scopes:

  • pymt:u



126
127
128
129
130
131
# File 'lib/beyond_api/resources/payment_methods.rb', line 126

def sort(payment_method_ids)
  body = payment_method_ids.map { |id| "#{@session.api_url}/payment-methods/#{id}" }
  response, status = BeyondApi::Request.put(@session, "/payment-methods", body)

  handle_response(response, status, respond_with_true: true)
end

#update(payment_method_id, body) ⇒ OpenStruct

A PUT request is used to update a payment method.

$ curl 'https://api-shop.beyondshop.cloud/api/payment-methods/dc00a5af-d21e-49f0-99f2-ef67ca6fa782' -i -X PUT \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/hal+json' \
    -H 'Authorization: Bearer <Access token>' \
    -d '{
        "name" : "Another name",
        "description" : "Pay by ACME.",
        "taxClass" : "REGULAR",
        "discountOrFee" : {
          "type" : "ABSOLUTE",
          "absoluteValue" : {
            "taxModel" : "GROSS",
            "currency" : "EUR",
            "amount" : 2.0
          }
        },
        "serviceableCountries" : [ "DE" ],
        "minimumOrderValue" : {
          "currency" : "EUR",
          "amount" : 10.0
        }
    }'

Examples:

body = {
  "name" => "Another name",
  "description" => "Pay by ACME.",
  "tax_class" => "REGULAR",
  "discount_or_fee" => {
    "type" => "ABSOLUTE",
    "absolute_value" => {
      "tax_model" => "GROSS",
      "currency" => "EUR",
      "amount" => 2.0
    }
  },
  "serviceable_countries" => [ "DE" ],
  "minimum_order_value" => {
    "currency" => "EUR",
    "amount" => 10.0
  }
}

@payment_method = session.payment_methods.update("dc00a5af-d21e-49f0-99f2-ef67ca6fa782", body)

Parameters:

  • payment_method_id (String)

    the payment method UUID

  • body (Hash)

    the request body

Returns:

  • (OpenStruct)

Scopes:

  • pymt:u



188
189
190
191
192
# File 'lib/beyond_api/resources/payment_methods.rb', line 188

def update(payment_method_id, body)
  response, status = BeyondApi::Request.put(@session, "/payment-methods/#{payment_method_id}", body)

  handle_response(response, status)
end