Class: PandaPay::Donation

Inherits:
Object
  • Object
show all
Defined in:
lib/pandapay/donation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Donation

Returns a new instance of Donation.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pandapay/donation.rb', line 5

def initialize(attributes)
	@id = attributes["id"]
	@object = attributes["object"]
	@created = attributes["created"]
	@livemode = attributes["livemode"]
	@charge_amount = attributes["charge_amount"]
	@platform_fee = attributes["platform_fee"]
	@donation_after_fees = attributes["donation_after_fees"]
	@currency = attributes["currency"]
	@payment_token = attributes["payment_token"]
	@customer = attributes["customer"]
	@grants = attributes["grants"]
	@receipt_email = attributes["receipt_email"]
	@destination = attributes["destination"]
	@restriction = attributes["restriction"]
end

Instance Attribute Details

#charge_amountObject (readonly)

Returns the value of attribute charge_amount.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def charge_amount
  @charge_amount
end

#createdObject (readonly)

Returns the value of attribute created.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def created
  @created
end

#currencyObject (readonly)

Returns the value of attribute currency.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def currency
  @currency
end

#customerObject (readonly)

Returns the value of attribute customer.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def customer
  @customer
end

#destinationObject (readonly)

Returns the value of attribute destination.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def destination
  @destination
end

#donation_after_feesObject (readonly)

Returns the value of attribute donation_after_fees.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def donation_after_fees
  @donation_after_fees
end

#grantsObject (readonly)

Returns the value of attribute grants.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def grants
  @grants
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def id
  @id
end

#livemodeObject (readonly)

Returns the value of attribute livemode.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def livemode
  @livemode
end

#objectObject (readonly)

Returns the value of attribute object.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def object
  @object
end

#payment_tokenObject (readonly)

Returns the value of attribute payment_token.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def payment_token
  @payment_token
end

#platform_feeObject (readonly)

Returns the value of attribute platform_fee.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def platform_fee
  @platform_fee
end

#receipt_emailObject (readonly)

Returns the value of attribute receipt_email.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def receipt_email
  @receipt_email
end

#restrictionObject (readonly)

Returns the value of attribute restriction.



3
4
5
# File 'lib/pandapay/donation.rb', line 3

def restriction
  @restriction
end

Class Method Details

.create(amount:, destination: "", restriction: "", source:, receipt_email:, platform_fee: "0", currency: "USD") ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/pandapay/donation.rb', line 22

def self.create(amount: , destination: "", restriction: "", source: , receipt_email: , platform_fee: "0", currency: "USD")
	conn = Faraday.new(:url => "https://#{PandaPay.secret_key}:@#{PandaPay_API_URL}")     
	response = conn.post '/v1/donations', { :amount => amount, :currency => currency, :source => source, :receipt_email => receipt_email, :platform_fee => platform_fee, :destination => destination, :restriction => restriction }
	attributes = JSON.parse(response.body)
	if attributes.has_key? "error" or attributes.has_key? "errors"
		raise response.body
	else 
		new(attributes)
	end
end