ruby-paypal 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'pp'
2
2
  require 'net/http'
3
3
  require 'net/https'
4
4
  require 'uri'
5
- require 'lib/ruby-paypal/credit_card_checks'
5
+ require 'ruby-paypal/credit_card_checks'
6
6
 
7
7
  SANDBOX_SERVER = 'api-3t.sandbox.paypal.com/nvp'
8
8
  PRODUCTION_SERVER = 'api-3t.paypal.com/nvp'
@@ -51,6 +51,13 @@ class PayPalResponse < Hash
51
51
  end
52
52
 
53
53
 
54
+ # Container used for mass payment
55
+ #
56
+ class PayPalPayment
57
+ attr_accessor :email, :receiver_id, :unique_id, :note, :amount
58
+ end
59
+
60
+
54
61
  =begin rdoc
55
62
  Author:: Chang Sau Sheong (mailto:sausheong.chang@gmail.com)
56
63
  Copyright:: Copyright (c) 2007 Chang Sau Sheong
@@ -297,6 +304,37 @@ class Paypal
297
304
  # stub for check to bindatabase.com, currently down
298
305
  end
299
306
 
307
+
308
+ # Perform mass payment to a group of recipients
309
+ #
310
+ # Equivalent to MassPay
311
+ #
312
+ def do_mass_payment(payments, email_subject, receiver_type='EmailAddress', currency_code='USD')
313
+ if receiver_type != 'EmailAddress' then
314
+ receiver_type = 'UserID'
315
+ end
316
+
317
+ params = {
318
+ 'METHOD' => 'MassPay',
319
+ 'RECEIVERTYPE' => receiver_type,
320
+ 'CURRENCYCODE' => currency_code,
321
+ 'EMAILSUBJECT' => email_subject
322
+ }
323
+
324
+ payments.each_index { |num|
325
+ if receiver_type == 'EmailAddress' then
326
+ params["L_EMAIL#{num}"] = payments[num].email
327
+ else
328
+ params["L_RECEIVERID#{num}"] = payments[num].receiver_id
329
+ end
330
+ params["L_UNIQUEID#{num}"] = payments[num].unique_id
331
+ params["L_NOTE#{num}"] = payments[num].note
332
+ params["L_AMT#{num}"] = payments[num].amount
333
+ }
334
+
335
+ make_nvp_call(params)
336
+ end
337
+
300
338
  private
301
339
 
302
340
  #
@@ -9,9 +9,10 @@ class RubyPayPal < Test::Unit::TestCase
9
9
  @test_data = {"visa" => "4154727623381301", "visa" => "4015262522324137", "visa" => "4574806205610007"}
10
10
  @paypal = Paypal.new('css.pa_1195828529_biz_api1.gmail.com', '1195828547', 'AJsoTDMhNESFz43L9WKtkP2tVCZZAZ3Wl.IxVLj8IfJQsjg8WZYMENpS')
11
11
  end
12
+
12
13
  def test_do_direct_payment_sale
13
- resp = @paypal.do_direct_payment_sale('202.156.13.1', '14.34', 'visa', '4574806205610007', '022017', 'Test', 'User')
14
- assert_equal("Success", resp.ack)
14
+ # resp = @paypal.do_direct_payment_sale('202.156.13.1', '14.34', 'visa', '4574806205610007', '022017', 'Test', 'User')
15
+ # assert_equal("Success", resp.ack)
15
16
  end
16
17
 
17
18
  def test_luhn_check
@@ -30,5 +31,27 @@ class RubyPayPal < Test::Unit::TestCase
30
31
 
31
32
  end
32
33
 
34
+ def test_do_mass_payment
35
+ payments = []
36
+ payment = PayPalPayment.new
37
+ payment.email = 'css.pa_1195828513_per@gmail.com'
38
+ payment.unique_id = '123'
39
+ payment.note = 'Hello there'
40
+ payment.amount = '5'
41
+ payments << payment
42
+
43
+ payment2 = PayPalPayment.new
44
+ payment2.email = 'css.pa_1195828286_per@gmail.com'
45
+ payment2.unique_id = '124'
46
+ payment2.note = 'Hello there2'
47
+ payment2.amount = '15'
48
+
49
+ payments << payment2
50
+
51
+ resp = @paypal.do_mass_payment(payments, "hello world")
52
+ assert_equal("Success", resp.ack)
53
+ end
54
+
55
+
33
56
  end
34
57
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ruby-paypal
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2008-01-02 00:00:00 +08:00
6
+ version: 0.0.3
7
+ date: 2008-01-30 00:00:00 +08:00
8
8
  summary: A lightweight Ruby wrapper for PayPal NVP API
9
9
  require_paths:
10
10
  - lib