Class: PayPal::OrdersResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/pay_pal/resources/orders.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from PayPal::Resource

Instance Method Details

#authorize(id:) ⇒ Object



54
55
56
57
# File 'lib/pay_pal/resources/orders.rb', line 54

def authorize(id:)
  response = post_request("v2/checkout/orders/#{id}/authorize", body: {})
  Order.new(response.body)
end

#capture(id:) ⇒ Object



59
60
61
62
# File 'lib/pay_pal/resources/orders.rb', line 59

def capture(id:)
  response = post_request("v2/checkout/orders/#{id}/capture", body: {})
  Order.new(response.body)
end

#create(intent:, units:, **params) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/pay_pal/resources/orders.rb', line 9

def create(intent:, units:, **params)
  attributes = {intent: intent.upcase, purchase_units: units}
  Order.new post_request("v2/checkout/orders", 
    body: attributes.merge(params),
    headers: {"Prefer" => "return=representation"}
  ).body
end

#create_payment(intent:, description:, currency:, value:, **params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pay_pal/resources/orders.rb', line 17

def create_payment(intent:, description:, currency:, value:, **params)
  items = [{
    description: description,
    amount: {
      currency_code: currency, value: value
    }
  }]

  attributes = {intent: intent.upcase, purchase_units: items}
  Order.new post_request("v2/checkout/orders", 
    body: attributes.merge(params),
    headers: {"Prefer" => "return=representation"}
  ).body
end

#create_single(intent:, title:, description:, currency:, value:, **params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pay_pal/resources/orders.rb', line 32

def create_single(intent:, title:, description:, currency:, value:, **params)
  items = [{
    items: [
      {name: title, description: description, quantity: 1, unit_amount: {currency_code: currency, value: value}}
    ],
    amount: {
      currency_code: currency, value: value,
      breakdown: {
        item_total: {
          currency_code: currency, value: value
        }
      }
    }
  }]

  attributes = {intent: intent.upcase, purchase_units: items}
  Order.new post_request("v2/checkout/orders", 
    body: attributes.merge(params),
    headers: {"Prefer" => "return=representation"}
  ).body
end

#retrieve(id:) ⇒ Object



4
5
6
7
# File 'lib/pay_pal/resources/orders.rb', line 4

def retrieve(id:)
  response = get_request("v2/checkout/orders/#{id}")
  Order.new(response.body)
end