Class: MerchantPaypal::Order

Inherits:
ApiResource show all
Extended by:
MerchantPaypal::Operations::Get
Defined in:
lib/merchant-paypal/order.rb

Class Method Summary collapse

Methods included from MerchantPaypal::Operations::Get

get

Methods inherited from ApiResource

class_name

Methods included from MerchantPaypal::Operations::Request

included

Class Method Details

.capture(id, opts = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/merchant-paypal/order.rb', line 35

def self.capture(id, opts = {})
  payload = {
    payment_source: {
      token: {
        id: id,
        type: "BILLING_AGREEMENT",
      }
    }
  }

  request(:post, "#{resource_url}/#{CGI.escape(id)}/capture", payload, opts)
end

.create(params = {}, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/merchant-paypal/order.rb', line 9

def self.create(params = {}, opts = {})
  payload = {
    intent: "CAPTURE",
    processing_instruction: "NO_INSTRUCTION",
    purchase_units: [{
      amount: {
        currency_code:  params[:currency] || "AUD",
        value: params[:amount],
      }
    }],
    application_context: {
      landing_page: "NO_PREFERENCE",
      user_action: "PAY_NOW",
      return_url: params[:return_url],
      cancel_url:  params[:cancel_url],
    }
  }

  request(:post, resource_url, payload, opts)
end

.create_for_redirection_url(params = {}, opts = {}) ⇒ Object



30
31
32
33
# File 'lib/merchant-paypal/order.rb', line 30

def self.create_for_redirection_url(params = {}, opts = {})
  response = self.create(params, opts)
  response.links.find { |link| link.rel == "approve"}&.href
end

.resource_urlObject



5
6
7
# File 'lib/merchant-paypal/order.rb', line 5

def self.resource_url
  "/v2/checkout/#{CGI.escape(class_name.tableize)}"
end