paypal_merchant 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/paypal/account.rb +5 -0
- data/lib/paypal/charge.rb +30 -0
- data/lib/paypal/merchant/do_direct_payment.rb +57 -0
- data/lib/paypal/merchant/mass_pay.rb +54 -0
- data/lib/paypal/merchant/reporting.rb +32 -0
- data/lib/paypal/merchant.rb +10 -0
- data/lib/paypal/transfer.rb +29 -0
- data/lib/paypal_merchant.rb +46 -0
- data/paypal_merchant.gemspec +14 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c8c08a3a6da70bf676050217f423daa8b77f192
|
4
|
+
data.tar.gz: 0804cef478ae29a8dd9feb7de344b0c9a804e98b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59ebde17a53294cb03fabcac23d3323b23b6da731c3d3901681bf7069e83de5e271e0aac9502b2ef96628aab39356a38718cf7982a80a3338516add8297b56a9
|
7
|
+
data.tar.gz: 713711c463e1b748229577b77966c8cc2bbc4693a6e3dd97d6201216d6729f3da5d94ca9a034bc5cdfcdceed19c4b967ad76aa734e35867265d257df2a555672
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PayPal
|
2
|
+
class Charge
|
3
|
+
include PayPal::Merchant::DoDirectPayment
|
4
|
+
|
5
|
+
attr_accessor :response
|
6
|
+
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def create(params = {})
|
10
|
+
new(params)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def initialize(params = {})
|
16
|
+
amount, card = params[:amount], params[:card]
|
17
|
+
if amount && card
|
18
|
+
@response = charge(amount, card, params)
|
19
|
+
else
|
20
|
+
raise "You must provide an amount and credit card"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def success?
|
26
|
+
@response && @response.try(:success?)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module PayPal
|
2
|
+
module Merchant
|
3
|
+
module DoDirectPayment
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
# Charge a credit card
|
8
|
+
#
|
9
|
+
def charge(amount, card, options = {currency: "USD"})
|
10
|
+
card.symbolize_keys!
|
11
|
+
begin
|
12
|
+
do_direct_payment_item = {
|
13
|
+
DoDirectPaymentRequestDetails: {
|
14
|
+
PaymentAction: options[:action] || "Sale",
|
15
|
+
PaymentDetails: {
|
16
|
+
OrderTotal: {
|
17
|
+
value: Money.new(amount).dollars,
|
18
|
+
currencyID: options[:currency] || "USD"
|
19
|
+
},
|
20
|
+
NotifyURL: options[:notify_url],
|
21
|
+
ShipToAddress: {
|
22
|
+
Name: options[:name],
|
23
|
+
Street1: options[:address],
|
24
|
+
CityName: options[:city],
|
25
|
+
StateOrProvince: options[:state],
|
26
|
+
Country: options[:country],
|
27
|
+
PostalCode: options[:postal_code]
|
28
|
+
}
|
29
|
+
},
|
30
|
+
CreditCard: {
|
31
|
+
CreditCardType: card[:type],
|
32
|
+
CreditCardNumber: card[:number],
|
33
|
+
ExpMonth: card[:exp_month],
|
34
|
+
ExpYear: card[:exp_year],
|
35
|
+
CVV2: card[:cvc_code]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
send_do_direct_payment(do_direct_payment_item)
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Make API call & get response
|
47
|
+
#
|
48
|
+
def send_do_direct_payment(do_direct_payment_item, options = {})
|
49
|
+
merchant_api = PayPal::Merchant.new
|
50
|
+
charge_request = merchant_api.build_do_direct_payment(do_direct_payment_item)
|
51
|
+
response = merchant_api.do_direct_payment(charge_request)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end # DoDirectPayment
|
56
|
+
end # Merchant
|
57
|
+
end # PayPal
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module PayPal
|
2
|
+
module Merchant
|
3
|
+
module MassPay
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
# Send money to another PayPal account
|
8
|
+
#
|
9
|
+
def transfer(amount, email, options = {currency: "USD"})
|
10
|
+
begin
|
11
|
+
mass_pay_item = {
|
12
|
+
ReceiverEmail: email,
|
13
|
+
Amount: {currencyID: options[:currency],
|
14
|
+
value: Money.new(amount).dollars}
|
15
|
+
}
|
16
|
+
send_mass_pay(mass_pay_item, options)
|
17
|
+
rescue
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Send money to multiple PayPal accounts
|
24
|
+
#
|
25
|
+
def bulk_transfer(recipients, options = {})
|
26
|
+
begin
|
27
|
+
mass_pay_item = recipients.map do |recipient|
|
28
|
+
recipient.symbolize_keys!
|
29
|
+
{ReceiverEmail: recipient[:email],
|
30
|
+
Amount: {
|
31
|
+
currencyID: options[:currency] || "USD",
|
32
|
+
value: Money.new(recipient[:amount]).dollars
|
33
|
+
}, Note: options[:note]}
|
34
|
+
end
|
35
|
+
send_mass_pay(mass_pay_item, options)
|
36
|
+
rescue
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def send_mass_pay(mass_pay_item, options = {})
|
43
|
+
merchant_api = PayPal::Merchant.new
|
44
|
+
transfer_request = merchant_api.build_mass_pay({
|
45
|
+
ReceiverType: "EmailAddress",
|
46
|
+
EmailSubject: options[:subject],
|
47
|
+
MassPayItem: [mass_pay_item].flatten
|
48
|
+
})
|
49
|
+
response = merchant_api.mass_pay(transfer_request)
|
50
|
+
end
|
51
|
+
|
52
|
+
end # MassPay
|
53
|
+
end # Merchant
|
54
|
+
end # PayPal
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PayPal
|
2
|
+
module Merchant
|
3
|
+
module Reporting
|
4
|
+
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# Get the balance of your PayPal account
|
13
|
+
#
|
14
|
+
# Returns an the balance in cents for the primary currency
|
15
|
+
# holding of the account).
|
16
|
+
#
|
17
|
+
def balance
|
18
|
+
merchant_api = PayPal::Merchant.new
|
19
|
+
balance_request = merchant_api.build_get_balance
|
20
|
+
response = merchant_api.get_balance(balance_request)
|
21
|
+
if response.success?
|
22
|
+
Money.parse(response.balance.value).cents
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end # ClassMethods
|
29
|
+
|
30
|
+
end # Reporting
|
31
|
+
end # Merchant
|
32
|
+
end # PayPal
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PayPal
|
2
|
+
class Transfer
|
3
|
+
include PayPal::Merchant::MassPay
|
4
|
+
|
5
|
+
attr_accessor :response
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def create(params = {})
|
9
|
+
new(params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def initialize(params = {})
|
15
|
+
amount, email = params[:amount], params[:email]
|
16
|
+
if amount && email
|
17
|
+
@response = self.transfer(amount, email, params)
|
18
|
+
else
|
19
|
+
raise "You must provide an amount and a recipient email address."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def success?
|
25
|
+
@response && @response.try(:success?)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'paypal-sdk-merchant'
|
2
|
+
require 'money'
|
3
|
+
require 'paypal/merchant'
|
4
|
+
require 'paypal/merchant/do_direct_payment'
|
5
|
+
require 'paypal/merchant/mass_pay'
|
6
|
+
require 'paypal/merchant/reporting'
|
7
|
+
require 'paypal/account'
|
8
|
+
require 'paypal/charge'
|
9
|
+
require 'paypal/transfer'
|
10
|
+
|
11
|
+
module PayPal
|
12
|
+
|
13
|
+
@mode = "sandbox"
|
14
|
+
|
15
|
+
@logger = PayPal::SDK::Core::Logging.logger
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_accessor :mode, :logger, :client_id, :client_secret, :username, :password, :signature
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configure(options = {})
|
22
|
+
@mode = options[:mode] || "sandbox"
|
23
|
+
@client_id = options[:client_id]
|
24
|
+
@client_secret = options[:client_secret]
|
25
|
+
@username = options[:username]
|
26
|
+
@password = options[:password]
|
27
|
+
@signature = options[:signature]
|
28
|
+
@logger = options[:logger]
|
29
|
+
configure_sdk
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.configure_sdk
|
35
|
+
PayPal::SDK::Core::Config.logger = @logger
|
36
|
+
PayPal::SDK.configure(
|
37
|
+
mode: @mode,
|
38
|
+
client_id: @client_id,
|
39
|
+
client_secret: @client_secret,
|
40
|
+
username: @username,
|
41
|
+
password: @password,
|
42
|
+
signature: @signature
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'paypal_merchant'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.summary = "Wrapper for PayPal's merchant-sdk-ruby library"
|
5
|
+
s.description = "Wrapper for PayPal's merchant-sdk-ruby library"
|
6
|
+
s.authors = ["Zach Ohlgren"]
|
7
|
+
s.email = 'zach@ohlgren.me'
|
8
|
+
|
9
|
+
s.add_dependency('paypal-sdk-merchant', '~> 1.103')
|
10
|
+
s.add_dependency('money', '~> 5.1')
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.require_path = "lib"
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paypal_merchant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zach Ohlgren
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: paypal-sdk-merchant
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.103'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.103'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: money
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.1'
|
41
|
+
description: Wrapper for PayPal's merchant-sdk-ruby library
|
42
|
+
email: zach@ohlgren.me
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/paypal/account.rb
|
48
|
+
- lib/paypal/charge.rb
|
49
|
+
- lib/paypal/merchant.rb
|
50
|
+
- lib/paypal/merchant/do_direct_payment.rb
|
51
|
+
- lib/paypal/merchant/mass_pay.rb
|
52
|
+
- lib/paypal/merchant/reporting.rb
|
53
|
+
- lib/paypal/transfer.rb
|
54
|
+
- lib/paypal_merchant.rb
|
55
|
+
- paypal_merchant.gemspec
|
56
|
+
homepage:
|
57
|
+
licenses: []
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.7
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Wrapper for PayPal's merchant-sdk-ruby library
|
79
|
+
test_files: []
|