Class: Paypal::Payment::Request
- Defined in:
- lib/paypal/payment/request.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Request
constructor
A new instance of Request.
- #items_amount ⇒ Object
- #to_params(index = 0) ⇒ Object
Methods included from Util
#==, formatted_amount, #numeric_attribute?, to_numeric
Constructor Details
#initialize(attributes = {}) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/paypal/payment/request.rb', line 7 def initialize(attributes = {}) @amount = if attributes[:amount].is_a?(Common::Amount) attributes[:amount] else Common::Amount.new( :total => attributes[:amount], :tax => attributes[:tax_amount], :shipping => attributes[:shipping_amount] ) end @items = [] Array(attributes[:items]).each do |item_attrs| @items << Item.new(item_attrs) end super end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'lib/paypal/payment/request.rb', line 5 def amount @amount end |
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/paypal/payment/request.rb', line 5 def items @items end |
Instance Method Details
#items_amount ⇒ Object
53 54 55 56 57 |
# File 'lib/paypal/payment/request.rb', line 53 def items_amount self.items.sum do |item| item.quantity * BigDecimal.new(item.amount.to_s) end end |
#to_params(index = 0) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/paypal/payment/request.rb', line 24 def to_params(index = 0) params = { :"PAYMENTREQUEST_#{index}_PAYMENTACTION" => self.action, :"PAYMENTREQUEST_#{index}_AMT" => Util.formatted_amount(self.amount.total), :"PAYMENTREQUEST_#{index}_TAXAMT" => Util.formatted_amount(self.amount.tax), :"PAYMENTREQUEST_#{index}_SHIPPINGAMT" => Util.formatted_amount(self.amount.shipping), :"PAYMENTREQUEST_#{index}_CURRENCYCODE" => self.currency_code, :"PAYMENTREQUEST_#{index}_DESC" => self.description, # NOTE: # notify_url works only when DoExpressCheckoutPayment called. # recurring payment doesn't support dynamic notify_url. :"PAYMENTREQUEST_#{index}_NOTIFYURL" => self.notify_url, :"L_BILLINGTYPE#{index}" => self.billing_type, :"L_BILLINGAGREEMENTDESCRIPTION#{index}" => self.billing_agreement_description, # FOR PARALLEL PAYMENT :"PAYMENTREQUEST_#{index}_PAYMENTREQUESTID" => self.request_id, :"PAYMENTREQUEST_#{index}_SELLERPAYPALACCOUNTID" => self.seller_id }.delete_if do |k, v| v.blank? end if self.items.present? params[:"PAYMENTREQUEST_#{index}_ITEMAMT"] = Util.formatted_amount(self.items_amount) self.items.each_with_index do |item, item_index| params.merge! item.to_params(index, item_index) end end params end |