Class: LolitaPaypal::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/lolita-paypal/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment = nil) ⇒ Request

Returns a new instance of Request.



6
7
8
# File 'lib/lolita-paypal/request.rb', line 6

def initialize(payment = nil)
  @payment = payment
end

Instance Attribute Details

#paymentObject (readonly)

Returns the value of attribute payment.



4
5
6
# File 'lib/lolita-paypal/request.rb', line 4

def payment
  @payment
end

Class Method Details

.encrypt_for_paypal(values) ⇒ Object



10
11
12
13
# File 'lib/lolita-paypal/request.rb', line 10

def self.encrypt_for_paypal(values)
  signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(LolitaPaypal.app_cert_pem), OpenSSL::PKey::RSA.new(LolitaPaypal.app_key_pem, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
  OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(LolitaPaypal.paypal_cert_pem)], signed.to_der, OpenSSL::Cipher::Cipher::new('DES3'), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end

Instance Method Details

#amount(money) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/lolita-paypal/request.rb', line 15

def amount(money)
  cents = money.respond_to?(:cents) ? money.cents : money
  if money.nil? || cents.to_i <= 0
    raise ArgumentError, 'money amount must be either a Money object or a positive integer in cents.'
  end
  sprintf("%.2f", cents.to_f / 100)
end

#payment_idObject



23
24
25
# File 'lib/lolita-paypal/request.rb', line 23

def payment_id
  payment.id
end

#request_variablesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lolita-paypal/request.rb', line 27

def request_variables
  {
    'cert_id' => LolitaPaypal.cert_id,
    'cmd' => '_xclick',
    'business' =>  LolitaPaypal.,
    'item_name' => payment.description,
    'custom' =>"#{payment.class.to_s.underscore}___#{payment_id}",
    'amount' => amount(payment.price),
    'currency_code' => payment.currency,
    'no_note' => '1',
    'no_shipping' => '1',
    'return' => payment.paypal_return_path
  }.merge(payment.paypal_request_variables)
end