Class: SlimpayClient::Order

Inherits:
Resource show all
Defined in:
lib/slimpay_client/order.rb

Overview

Inherits from Resouce and thus defines its associated resource’s methods.

Defines shortcut methods for the create_order method with various arguments.

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Methods inherited from Base

#generate_api_methods, #initialize

Constructor Details

This class inherits a constructor from SlimpayClient::Resource

Instance Method Details

#get_one(reference = 1) ⇒ Object

Override the Resource#get_one method because the url is not the same for Orders

Example:
orders = SlimpayClient::Order.new
orders.get_one
=>
  {"_links"=>
    {"self"=>{"href"=>"https://api-sandbox.slimpay.net/creditors/democreditor/orders/1"},
     "https://api.slimpay.net/alps#get-creditor"=>{"href"=>"https://api-sandbox.slimpay.net/creditors/democreditor"},
     "https://api.slimpay.net/alps#get-subscriber" =>
        {"href"=>"https://api-sandbox.slimpay.net/creditors/democreditor/orders/1/subscribers/subscriber01"},
     "https://api.slimpay.net/alps#user-approval" =>
        {"href"=>"https://slimpay.net/slimpaytpe16/userApproval?accessCode=spK534N0cuZztBGwj2FjC6eKzcsKFRzXbfy8buloUHiZV6p9PhIfcPgV7c507R"},
     "https://api.slimpay.net/alps#get-order-items"=>{"href"=>"https://api-sandbox.slimpay.net/creditors/democreditor/orders/1/items"},
     "https://api.slimpay.net/alps#get-mandate"=>{"href"=>"https://api-sandbox.slimpay.net/creditors/democreditor/mandates/1"}},
   "reference"=>"1",
   "state"=>"closed.completed",
   "started"=>true,
   "dateCreated"=>"2014-12-12T09:35:39.000+0000",
   "mandateReused"=>false}
Arguments:
reference: (String)


28
29
30
31
32
# File 'lib/slimpay_client/order.rb', line 28

def get_one(reference = 1)
  query_options = "creditorReference=#{@creditor_reference}&reference=#{reference}"
  response = HTTParty.get("#{@endpoint}/#{@resource_name}?#{query_options}", headers: options)
  follow_up_api(response)
end

#login(reference = 'subscriber01') ⇒ Object

POST



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/slimpay_client/order.rb', line 35

def (reference = 'subscriber01')
  url = 'orders'
  body_options = {
    creditor: {
      reference: @creditor_reference
    },
    subscriber: {
      reference: reference
    },
    items: [
      {
        type: 'subscriberLogin'
      }
    ],
    started: true
  }
  response = HTTParty.post("#{@endpoint}/#{url}", body: body_options.to_json, headers: options)
  follow_up_api(response)
end

#sign_mandate(reference = 'subscriber01', signatory = default_signatory) ⇒ Object

POST This will send a create_order request with given signatory (subscriber Hash with infos)

In case of success, this will generate a method accessible via the .api_methods method. This method let you redirect the customer to the approval page : orders.api_methods

Arguments
reference: (String) The reference to your User in your application. Use a unique key. SlimpayClient will refer to it for future answers.
signatory: (Hash) Your customer informations. See API Order documentation for details.
Returns
a Hash representing the Mandate.


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/slimpay_client/order.rb', line 65

def sign_mandate(reference = 'subscriber01', signatory = default_signatory)
  url = 'orders'
  body_options = {
    creditor: {
      reference: @creditor_reference
    },
    subscriber: {
      reference: reference
    },
    items: [
      {
        type: 'signMandate',
        mandate: {
          standard: 'SEPA',
          signatory: signatory
        }
      }
    ],
    started: true
  }
  response = HTTParty.post("#{@endpoint}/#{url}", body: body_options.to_json, headers: options)
  JSON.parse(follow_up_api(response))
end