killbill-paypal-express 1.0.17 → 1.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.
data/Jarfile CHANGED
@@ -1,3 +1,5 @@
1
- jar 'com.ning.billing:killbill-api', '0.1.80'
2
- jar 'com.ning.billing:killbill-util:tests', '0.1.80'
1
+ jar 'com.ning.billing:killbill-api', '0.3.0'
2
+ jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.2.4'
3
+ jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.2.4'
4
+ jar 'com.ning.billing:killbill-util:tests', '0.2.6-SNAPSHOT'
3
5
  jar 'javax.servlet:javax.servlet-api', '3.0.1'
data/NEWS ADDED
@@ -0,0 +1,2 @@
1
+ 1.1.0
2
+ Update to killbill 1.1.2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.17
1
+ 1.1.0
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.rdoc_options << '--exclude' << '.'
24
24
 
25
- s.add_dependency 'killbill', '~> 1.0.19'
25
+ s.add_dependency 'killbill', '~> 1.1.2'
26
26
  s.add_dependency 'activemerchant', '~> 2.0.0'
27
27
  s.add_dependency 'activerecord', '~> 3.2.1'
28
28
  s.add_dependency 'sinatra', '~> 1.3.4'
@@ -16,19 +16,19 @@ module Killbill::PaypalExpress
16
16
  ActiveRecord::Base.connection.close
17
17
  end
18
18
 
19
- def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context, options = {})
19
+ def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context = nil, options = {})
20
20
  # If the payment was already made, just return the status
21
- paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id.to_s) rescue nil
21
+ paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id) rescue nil
22
22
  return paypal_express_transaction.paypal_express_response.to_payment_response unless paypal_express_transaction.nil?
23
23
 
24
- options[:currency] ||= currency.respond_to?(:enum) ? currency.enum : currency.to_s
24
+ options[:currency] ||= currency.to_s
25
25
  options[:payment_type] ||= 'Any'
26
- options[:invoice_id] ||= kb_payment_id.to_s
26
+ options[:invoice_id] ||= kb_payment_id
27
27
  options[:description] ||= "Kill Bill payment for #{kb_payment_id}"
28
28
  options[:ip] ||= @ip
29
29
 
30
30
  if options[:reference_id].blank?
31
- payment_method = PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s)
31
+ payment_method = PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id)
32
32
  options[:reference_id] = payment_method.paypal_express_baid
33
33
  end
34
34
 
@@ -39,23 +39,23 @@ module Killbill::PaypalExpress
39
39
  response.to_payment_response
40
40
  end
41
41
 
42
- def get_payment_info(kb_account_id, kb_payment_id, tenant_context, options = {})
43
- paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id.to_s)
42
+ def get_payment_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
43
+ paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id)
44
44
 
45
45
  begin
46
46
  transaction_id = paypal_express_transaction.paypal_express_txn_id
47
47
  response = @gateway.transaction_details transaction_id
48
- PaypalExpressResponse.from_response(:transaction_details, kb_payment_id.to_s, response).to_payment_response
48
+ PaypalExpressResponse.from_response(:transaction_details, kb_payment_id, response).to_payment_response
49
49
  rescue => e
50
- @logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id.to_s}, defaulting to cached response: #{e}")
50
+ @logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id}, defaulting to cached response: #{e}")
51
51
  paypal_express_transaction.paypal_express_response.to_payment_response
52
52
  end
53
53
  end
54
54
 
55
- def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context, options = {})
56
- paypal_express_transaction = PaypalExpressTransaction.find_candidate_transaction_for_refund(kb_payment_id.to_s, amount_in_cents)
55
+ def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context = nil, options = {})
56
+ paypal_express_transaction = PaypalExpressTransaction.find_candidate_transaction_for_refund(kb_payment_id, amount_in_cents)
57
57
 
58
- options[:currency] ||= currency.respond_to?(:enum) ? currency.enum : currency.to_s
58
+ options[:currency] ||= currency.to_s
59
59
  options[:refund_type] ||= paypal_express_transaction.amount_in_cents != amount_in_cents ? 'Partial' : 'Full'
60
60
 
61
61
  identification = paypal_express_transaction.paypal_express_txn_id
@@ -67,25 +67,25 @@ module Killbill::PaypalExpress
67
67
  response.to_refund_response
68
68
  end
69
69
 
70
- def get_refund_info(kb_account_id, kb_payment_id, tenant_context, options = {})
71
- paypal_express_transaction = PaypalExpressTransaction.refund_from_kb_payment_id(kb_payment_id.to_s)
70
+ def get_refund_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
71
+ paypal_express_transaction = PaypalExpressTransaction.refund_from_kb_payment_id(kb_payment_id)
72
72
 
73
73
  begin
74
74
  transaction_id = paypal_express_transaction.paypal_express_txn_id
75
75
  response = @gateway.transaction_details transaction_id
76
- PaypalExpressResponse.from_response(:transaction_details, kb_payment_id.to_s, response).to_refund_response
76
+ PaypalExpressResponse.from_response(:transaction_details, kb_payment_id, response).to_refund_response
77
77
  rescue => e
78
- @logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id.to_s}, defaulting to cached response: #{e}")
78
+ @logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id}, defaulting to cached response: #{e}")
79
79
  paypal_express_transaction.paypal_express_response.to_refund_response
80
80
  end
81
81
  end
82
82
 
83
- def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, call_context, options = {})
83
+ def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default = false, call_context = nil, options = {})
84
84
  token = (payment_method_props.properties.find { |kv| kv.key == 'token' }).value
85
85
  return false if token.nil?
86
86
 
87
87
  # The payment method should have been created during the setup step (see private api)
88
- payment_method = PaypalExpressPaymentMethod.from_kb_account_id_and_token(kb_account_id.to_s, token)
88
+ payment_method = PaypalExpressPaymentMethod.from_kb_account_id_and_token(kb_account_id, token)
89
89
 
90
90
  # Go to Paypal to get the Payer id (GetExpressCheckoutDetails call)
91
91
  paypal_express_details_response = @gateway.details_for token
@@ -99,39 +99,39 @@ module Killbill::PaypalExpress
99
99
  response = save_response_and_transaction paypal_express_baid_response, :create_billing_agreement
100
100
  return false unless response.success?
101
101
 
102
- payment_method.kb_payment_method_id = kb_payment_method_id.to_s
102
+ payment_method.kb_payment_method_id = kb_payment_method_id
103
103
  payment_method.paypal_express_payer_id = payer_id
104
104
  payment_method.paypal_express_baid = response.billing_agreement_id
105
105
  payment_method.save!
106
106
 
107
- logger.info "Created BAID #{payment_method.paypal_express_baid} for payment method #{kb_payment_method_id.to_s} (account #{kb_account_id.to_s})"
107
+ logger.info "Created BAID #{payment_method.paypal_express_baid} for payment method #{kb_payment_method_id} (account #{kb_account_id})"
108
108
  true
109
109
  else
110
- logger.warn "Unable to retrieve Payer id details for token #{token} (account #{kb_account_id.to_s})"
110
+ logger.warn "Unable to retrieve Payer id details for token #{token} (account #{kb_account_id})"
111
111
  false
112
112
  end
113
113
  end
114
114
 
115
- def delete_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
116
- PaypalExpressPaymentMethod.mark_as_deleted! kb_payment_method_id.to_s
115
+ def delete_payment_method(kb_account_id, kb_payment_method_id, call_context = nil, options = {})
116
+ PaypalExpressPaymentMethod.mark_as_deleted! kb_payment_method_id
117
117
  end
118
118
 
119
- def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context, options = {})
120
- PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s).to_payment_method_response
119
+ def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context = nil, options = {})
120
+ PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id).to_payment_method_response
121
121
  end
122
122
 
123
- def set_default_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
123
+ def set_default_payment_method(kb_account_id, kb_payment_method_id, call_context = nil, options = {})
124
124
  # No-op
125
125
  end
126
126
 
127
- def get_payment_methods(kb_account_id, refresh_from_gateway, call_context, options = {})
128
- PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id.to_s).collect { |pm| pm.to_payment_method_info_response }
127
+ def get_payment_methods(kb_account_id, refresh_from_gateway, call_context = nil, options = {})
128
+ PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id).collect { |pm| pm.to_payment_method_info_response }
129
129
  end
130
130
 
131
131
  def reset_payment_methods(kb_account_id, payment_methods)
132
132
  return if payment_methods.nil?
133
133
 
134
- paypal_pms = PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id.to_s)
134
+ paypal_pms = PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id)
135
135
 
136
136
  payment_methods.delete_if do |payment_method_info_plugin|
137
137
  should_be_deleted = false
@@ -139,12 +139,12 @@ module Killbill::PaypalExpress
139
139
  # Do paypal_pm and payment_method_info_plugin represent the same PayPal payment method?
140
140
  if paypal_pm.external_payment_method_id == payment_method_info_plugin.external_payment_method_id
141
141
  # Do we already have a kb_payment_method_id?
142
- if paypal_pm.kb_payment_method_id == payment_method_info_plugin.payment_method_id.to_s
142
+ if paypal_pm.kb_payment_method_id == payment_method_info_plugin.payment_method_id
143
143
  should_be_deleted = true
144
144
  break
145
145
  elsif paypal_pm.kb_payment_method_id.nil?
146
146
  # We didn't have the kb_payment_method_id - update it
147
- paypal_pm.kb_payment_method_id = payment_method_info_plugin.payment_method_id.to_s
147
+ paypal_pm.kb_payment_method_id = payment_method_info_plugin.payment_method_id
148
148
  should_be_deleted = paypal_pm.save
149
149
  break
150
150
  # Otherwise the same BAID points to 2 different kb_payment_method_id. This should never happen,
@@ -158,8 +158,8 @@ module Killbill::PaypalExpress
158
158
 
159
159
  # The remaining elements in payment_methods are not in our table (this should never happen?!)
160
160
  payment_methods.each do |payment_method_info_plugin|
161
- PaypalExpressPaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id.to_s,
162
- :kb_payment_method_id => payment_method_info_plugin.payment_method_id.to_s,
161
+ PaypalExpressPaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id,
162
+ :kb_payment_method_id => payment_method_info_plugin.payment_method_id,
163
163
  :paypal_express_baid => payment_method_info_plugin.external_payment_method_id,
164
164
  :paypal_express_token => 'unknown (created by reset)'
165
165
  end
@@ -171,12 +171,12 @@ module Killbill::PaypalExpress
171
171
  @logger.warn "Unsuccessful #{api_call}: #{paypal_express_response.message}" unless paypal_express_response.success?
172
172
 
173
173
  # Save the response to our logs
174
- response = PaypalExpressResponse.from_response(api_call, kb_payment_id.to_s, paypal_express_response)
174
+ response = PaypalExpressResponse.from_response(api_call, kb_payment_id, paypal_express_response)
175
175
  response.save!
176
176
 
177
177
  if response.success and !kb_payment_id.blank? and !response.authorization.blank?
178
178
  # Record the transaction
179
- transaction = response.create_paypal_express_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id.to_s, :paypal_express_txn_id => response.authorization)
179
+ transaction = response.create_paypal_express_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id, :paypal_express_txn_id => response.authorization)
180
180
  @logger.debug "Recorded transaction: #{transaction.inspect}"
181
181
  end
182
182
  response
@@ -35,52 +35,57 @@ module Killbill::PaypalExpress
35
35
 
36
36
  def to_payment_method_response
37
37
  properties = []
38
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'payerId', paypal_express_payer_id)
39
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'baid', paypal_express_baid)
40
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'token', paypal_express_token)
38
+ properties << create_pm_kv_info('payerId', paypal_express_payer_id)
39
+ properties << create_pm_kv_info('baid', paypal_express_baid)
40
+ properties << create_pm_kv_info('token', paypal_express_token)
41
41
 
42
42
  # We're pretty much guaranteed to have a (single) entry for details_for, since it was called during add_payment_method
43
43
  details_for = PaypalExpressResponse.find_all_by_api_call_and_token('details_for', paypal_express_token).last
44
44
  unless details_for.nil?
45
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'payerName', details_for.payer_name)
46
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'payerEmail', details_for.payer_email)
47
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'payerCountry', details_for.payer_country)
48
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'contactPhone', details_for.contact_phone)
49
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressName', details_for.ship_to_address_name)
50
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressCompany', details_for.ship_to_address_company)
51
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressAddress1', details_for.ship_to_address_address1)
52
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressAddress2', details_for.ship_to_address_address2)
53
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressCity', details_for.ship_to_address_city)
54
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressState', details_for.ship_to_address_state)
55
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressCountry', details_for.ship_to_address_country)
56
- properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'shipToAddressZip', details_for.ship_to_address_zip)
45
+ properties << create_pm_kv_info('payerName', details_for.payer_name)
46
+ properties << create_pm_kv_info('payerEmail', details_for.payer_email)
47
+ properties << create_pm_kv_info('payerCountry', details_for.payer_country)
48
+ properties << create_pm_kv_info('contactPhone', details_for.contact_phone)
49
+ properties << create_pm_kv_info('shipToAddressName', details_for.ship_to_address_name)
50
+ properties << create_pm_kv_info('shipToAddressCompany', details_for.ship_to_address_company)
51
+ properties << create_pm_kv_info('shipToAddressAddress1', details_for.ship_to_address_address1)
52
+ properties << create_pm_kv_info('shipToAddressAddress2', details_for.ship_to_address_address2)
53
+ properties << create_pm_kv_info('shipToAddressCity', details_for.ship_to_address_city)
54
+ properties << create_pm_kv_info('shipToAddressState', details_for.ship_to_address_state)
55
+ properties << create_pm_kv_info('shipToAddressCountry', details_for.ship_to_address_country)
56
+ properties << create_pm_kv_info('shipToAddressZip', details_for.ship_to_address_zip)
57
57
  end
58
58
 
59
- Killbill::Plugin::Model::PaymentMethodPlugin.new(external_payment_method_id,
60
- is_default,
61
- properties,
62
- nil,
63
- 'PayPal',
64
- nil,
65
- nil,
66
- nil,
67
- nil,
68
- nil,
69
- nil,
70
- nil,
71
- nil,
72
- nil,
73
- nil,
74
- nil)
59
+ pm_plugin = Killbill::Plugin::Model::PaymentMethodPlugin.new
60
+ pm_plugin.external_payment_method_id = external_payment_method_id
61
+ pm_plugin.is_default_payment_method = is_default
62
+ pm_plugin.properties = properties
63
+ pm_plugin.type = 'PayPal'
64
+
65
+ pm_plugin
75
66
  end
76
67
 
77
68
  def to_payment_method_info_response
78
- Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
69
+ pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
70
+ pm_info_plugin.account_id = kb_account_id
71
+ pm_info_plugin.payment_method_id = kb_payment_method_id
72
+ pm_info_plugin.is_default = is_default
73
+ pm_info_plugin.external_payment_method_id = external_payment_method_id
74
+ pm_info_plugin
79
75
  end
80
76
 
81
77
  def is_default
82
78
  # No concept of default payment method in Paypal Express
83
79
  false
84
80
  end
81
+
82
+ private
83
+
84
+ def create_pm_kv_info(key, value)
85
+ prop = Killbill::Plugin::Model::PaymentMethodKVInfo.new
86
+ prop.key = key
87
+ prop.value = value
88
+ prop
89
+ end
85
90
  end
86
91
  end
@@ -57,58 +57,58 @@ module Killbill::PaypalExpress
57
57
 
58
58
  def self.from_response(api_call, kb_payment_id, response)
59
59
  PaypalExpressResponse.new({
60
- :api_call => api_call,
61
- :kb_payment_id => kb_payment_id,
62
- :message => response.message,
63
- :authorization => response.authorization,
64
- :fraud_review => response.fraud_review?,
65
- :test => response.test?,
66
- :token => response.token,
67
- :payer_id => response.payer_id,
68
- :billing_agreement_id => response.params['billing_agreement_id'],
69
- :payer_name => response.name,
70
- :payer_email => response.email,
71
- :payer_country => response.payer_country,
72
- :contact_phone => response.contact_phone,
73
- :ship_to_address_name => response.address['name'],
74
- :ship_to_address_company => response.address['company'],
75
- :ship_to_address_address1 => response.address['address1'],
76
- :ship_to_address_address2 => response.address['address2'],
77
- :ship_to_address_city => response.address['city'],
78
- :ship_to_address_state => response.address['state'],
79
- :ship_to_address_country => response.address['country'],
80
- :ship_to_address_zip => response.address['zip'],
81
- :ship_to_address_phone => response.address['phone'],
82
- :receiver_info_business => receiver_info(response)['Business'],
83
- :receiver_info_receiver => receiver_info(response)['Receiver'],
84
- :receiver_info_receiverid => receiver_info(response)['ReceiverID'],
85
- :payment_info_transactionid => payment_info(response)['TransactionID'],
86
- :payment_info_parenttransactionid => payment_info(response)['ParentTransactionID'],
87
- :payment_info_receiptid => payment_info(response)['ReceiptID'],
88
- :payment_info_transactiontype => payment_info(response)['TransactionType'],
89
- :payment_info_paymenttype => payment_info(response)['PaymentType'],
90
- :payment_info_paymentdate => payment_info(response)['PaymentDate'],
91
- :payment_info_grossamount => payment_info(response)['GrossAmount'],
92
- :payment_info_feeamount => payment_info(response)['FeeAmount'],
93
- :payment_info_taxamount => payment_info(response)['TaxAmount'],
94
- :payment_info_exchangerate => payment_info(response)['ExchangeRate'],
95
- :payment_info_paymentstatus => payment_info(response)['PaymentStatus'],
96
- :payment_info_pendingreason => payment_info(response)['PendingReason'],
97
- :payment_info_reasoncode => payment_info(response)['ReasonCode'],
98
- :payment_info_protectioneligibility => payment_info(response)['ProtectionEligibility'],
99
- :payment_info_protectioneligibilitytype => payment_info(response)['ProtectionEligibilityType'],
100
- :payment_info_shipamount => payment_info(response)['ShipAmount'],
101
- :payment_info_shiphandleamount => payment_info(response)['ShipHandleAmount'],
102
- :payment_info_shipdiscount => payment_info(response)['ShipDiscount'],
103
- :payment_info_insuranceamount => payment_info(response)['InsuranceAmount'],
104
- :payment_info_subject => payment_info(response)['Subject'],
105
- :avs_result_code => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.code : response.avs_result['code'],
106
- :avs_result_message => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.message : response.avs_result['message'],
107
- :avs_result_street_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.street_match : response.avs_result['street_match'],
108
- :avs_result_postal_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.postal_match : response.avs_result['postal_match'],
109
- :cvv_result_code => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.code : response.cvv_result['code'],
110
- :cvv_result_message => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.message : response.cvv_result['message'],
111
- :success => response.success?
60
+ :api_call => api_call,
61
+ :kb_payment_id => kb_payment_id,
62
+ :message => response.message,
63
+ :authorization => response.authorization,
64
+ :fraud_review => response.fraud_review?,
65
+ :test => response.test?,
66
+ :token => response.token,
67
+ :payer_id => response.payer_id,
68
+ :billing_agreement_id => response.params['billing_agreement_id'],
69
+ :payer_name => response.name,
70
+ :payer_email => response.email,
71
+ :payer_country => response.payer_country,
72
+ :contact_phone => response.contact_phone,
73
+ :ship_to_address_name => response.address['name'],
74
+ :ship_to_address_company => response.address['company'],
75
+ :ship_to_address_address1 => response.address['address1'],
76
+ :ship_to_address_address2 => response.address['address2'],
77
+ :ship_to_address_city => response.address['city'],
78
+ :ship_to_address_state => response.address['state'],
79
+ :ship_to_address_country => response.address['country'],
80
+ :ship_to_address_zip => response.address['zip'],
81
+ :ship_to_address_phone => response.address['phone'],
82
+ :receiver_info_business => receiver_info(response)['Business'],
83
+ :receiver_info_receiver => receiver_info(response)['Receiver'],
84
+ :receiver_info_receiverid => receiver_info(response)['ReceiverID'],
85
+ :payment_info_transactionid => payment_info(response)['TransactionID'],
86
+ :payment_info_parenttransactionid => payment_info(response)['ParentTransactionID'],
87
+ :payment_info_receiptid => payment_info(response)['ReceiptID'],
88
+ :payment_info_transactiontype => payment_info(response)['TransactionType'],
89
+ :payment_info_paymenttype => payment_info(response)['PaymentType'],
90
+ :payment_info_paymentdate => payment_info(response)['PaymentDate'],
91
+ :payment_info_grossamount => payment_info(response)['GrossAmount'],
92
+ :payment_info_feeamount => payment_info(response)['FeeAmount'],
93
+ :payment_info_taxamount => payment_info(response)['TaxAmount'],
94
+ :payment_info_exchangerate => payment_info(response)['ExchangeRate'],
95
+ :payment_info_paymentstatus => payment_info(response)['PaymentStatus'],
96
+ :payment_info_pendingreason => payment_info(response)['PendingReason'],
97
+ :payment_info_reasoncode => payment_info(response)['ReasonCode'],
98
+ :payment_info_protectioneligibility => payment_info(response)['ProtectionEligibility'],
99
+ :payment_info_protectioneligibilitytype => payment_info(response)['ProtectionEligibilityType'],
100
+ :payment_info_shipamount => payment_info(response)['ShipAmount'],
101
+ :payment_info_shiphandleamount => payment_info(response)['ShipHandleAmount'],
102
+ :payment_info_shipdiscount => payment_info(response)['ShipDiscount'],
103
+ :payment_info_insuranceamount => payment_info(response)['InsuranceAmount'],
104
+ :payment_info_subject => payment_info(response)['Subject'],
105
+ :avs_result_code => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.code : response.avs_result['code'],
106
+ :avs_result_message => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.message : response.avs_result['message'],
107
+ :avs_result_street_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.street_match : response.avs_result['street_match'],
108
+ :avs_result_postal_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.postal_match : response.avs_result['postal_match'],
109
+ :cvv_result_code => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.code : response.cvv_result['code'],
110
+ :cvv_result_message => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.message : response.cvv_result['message'],
111
+ :success => response.success?
112
112
  })
113
113
  end
114
114
 
@@ -146,11 +146,26 @@ module Killbill::PaypalExpress
146
146
  gateway_error_code = nil
147
147
 
148
148
  if type == :payment
149
- status = success ? Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED) : Killbill::Plugin::Model::PaymentPluginStatus.new(:ERROR)
150
- Killbill::Plugin::Model::PaymentInfoPlugin.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code, first_payment_reference_id, second_payment_reference_id)
149
+ p_info_plugin = Killbill::Plugin::Model::PaymentInfoPlugin.new
150
+ p_info_plugin.amount = amount_in_cents
151
+ p_info_plugin.created_date = created_date
152
+ p_info_plugin.effective_date = effective_date
153
+ p_info_plugin.status = (success ? :PROCESSED : :ERROR)
154
+ p_info_plugin.gateway_error = gateway_error
155
+ p_info_plugin.gateway_error_code = gateway_error_code
156
+ p_info_plugin.first_payment_reference_id = first_payment_reference_id
157
+ p_info_plugin.second_payment_reference_id = second_payment_reference_id
158
+ p_info_plugin
151
159
  else
152
- status = success ? Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED) : Killbill::Plugin::Model::RefundPluginStatus.new(:ERROR)
153
- Killbill::Plugin::Model::RefundInfoPlugin.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code, first_payment_reference_id)
160
+ r_info_plugin = Killbill::Plugin::Model::RefundInfoPlugin.new
161
+ r_info_plugin.amount = amount_in_cents
162
+ r_info_plugin.created_date = created_date
163
+ r_info_plugin.effective_date = effective_date
164
+ r_info_plugin.status = (success ? :PROCESSED : :ERROR)
165
+ r_info_plugin.gateway_error = gateway_error
166
+ r_info_plugin.gateway_error_code = gateway_error_code
167
+ r_info_plugin.reference_id = first_payment_reference_id
168
+ r_info_plugin
154
169
  end
155
170
  end
156
171
 
data/pom.xml CHANGED
@@ -25,7 +25,7 @@
25
25
  <groupId>com.ning.killbill.ruby</groupId>
26
26
  <artifactId>paypal-express-plugin</artifactId>
27
27
  <packaging>pom</packaging>
28
- <version>1.0.17</version>
28
+ <version>1.1.0</version>
29
29
  <name>paypal-express-plugin</name>
30
30
  <url>http://github.com/killbill/killbill-paypal-express-plugin</url>
31
31
  <description>Plugin for accessing paypal as a payment gateway</description>
@@ -45,9 +45,9 @@ describe Killbill::PaypalExpress::PaymentPlugin do
45
45
  # Add some in KillBill and reset
46
46
  payment_methods = []
47
47
  # Random order... Shouldn't matter...
48
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-3', false, 'paypal-3')
49
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-2', false, 'paypal-2')
50
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-4', false, 'paypal-4')
48
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-3', false, 'paypal-3')
49
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-2', false, 'paypal-2')
50
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-4', false, 'paypal-4')
51
51
  @plugin.reset_payment_methods kb_account_id, payment_methods
52
52
  verify_pms kb_account_id, 4
53
53
 
@@ -58,7 +58,7 @@ describe Killbill::PaypalExpress::PaymentPlugin do
58
58
  @plugin.get_payment_methods(kb_account_id, false, nil).size.should == 5
59
59
 
60
60
  # Verify we can match it
61
- payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-5', false, 'paypal-5')
61
+ payment_methods << create_pm_info_plugin(kb_account_id, 'kb-5', false, 'paypal-5')
62
62
  @plugin.reset_payment_methods kb_account_id, payment_methods
63
63
  verify_pms kb_account_id, 5
64
64
 
@@ -76,4 +76,13 @@ describe Killbill::PaypalExpress::PaymentPlugin do
76
76
  pm.external_payment_method_id.should == 'paypal-' + pm.payment_method_id.split('-')[1]
77
77
  end
78
78
  end
79
+
80
+ def create_pm_info_plugin(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
81
+ pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
82
+ pm_info_plugin.account_id = kb_account_id
83
+ pm_info_plugin.payment_method_id = kb_payment_method_id
84
+ pm_info_plugin.is_default = is_default
85
+ pm_info_plugin.external_payment_method_id = external_payment_method_id
86
+ pm_info_plugin
87
+ end
79
88
  end
@@ -15,47 +15,38 @@ describe Killbill::PaypalExpress::PaymentPlugin do
15
15
  @plugin.start_plugin
16
16
 
17
17
  @pm = create_payment_method
18
- @call_context = Killbill::Plugin::Model::CallContext.new(SecureRandom.uuid,
19
- 'token',
20
- 'rspec tester',
21
- 'TEST',
22
- 'user',
23
- 'testing',
24
- 'this is from a test',
25
- Time.now,
26
- Time.now)
27
18
  end
28
19
 
29
20
  after(:each) do
30
21
  @plugin.stop_plugin
31
22
  end
32
23
 
33
- it "should be able to charge and refund" do
24
+ it 'should be able to charge and refund' do
34
25
  amount_in_cents = 10000
35
26
  currency = 'USD'
36
27
  kb_payment_id = SecureRandom.uuid
37
28
 
38
- payment_response = @plugin.process_payment @pm.kb_account_id, kb_payment_id, @pm.kb_payment_method_id, amount_in_cents, currency, @call_context
29
+ payment_response = @plugin.process_payment @pm.kb_account_id, kb_payment_id, @pm.kb_payment_method_id, amount_in_cents, currency
39
30
  payment_response.amount.should == amount_in_cents
40
- payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
31
+ payment_response.status.should == :PROCESSED
41
32
 
42
33
  # Verify our table directly
43
34
  response = Killbill::PaypalExpress::PaypalExpressResponse.find_by_api_call_and_kb_payment_id :charge, kb_payment_id
44
35
  response.test.should be_true
45
36
  response.success.should be_true
46
- response.message.should == "Success"
37
+ response.message.should == 'Success'
47
38
 
48
39
  # Check we can retrieve the payment
49
- payment_response = @plugin.get_payment_info @pm.kb_account_id, kb_payment_id, @call_context
40
+ payment_response = @plugin.get_payment_info @pm.kb_account_id, kb_payment_id
50
41
  payment_response.amount.should == amount_in_cents
51
- payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
42
+ payment_response.status.should == :PROCESSED
52
43
 
53
44
  # Check we cannot refund an amount greater than the original charge
54
- lambda { @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency, @call_context }.should raise_error RuntimeError
45
+ lambda { @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency }.should raise_error RuntimeError
55
46
 
56
- refund_response = @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents, currency, @call_context
47
+ refund_response = @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents, currency
57
48
  refund_response.amount.should == amount_in_cents
58
- refund_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
49
+ refund_response.status.should == :PROCESSED
59
50
 
60
51
  # Verify our table directly
61
52
  response = Killbill::PaypalExpress::PaypalExpressResponse.find_by_api_call_and_kb_payment_id :refund, kb_payment_id
@@ -63,36 +54,36 @@ describe Killbill::PaypalExpress::PaymentPlugin do
63
54
  response.success.should be_true
64
55
 
65
56
  # Check we can retrieve the refund
66
- refund_response = @plugin.get_refund_info @pm.kb_account_id, kb_payment_id, @call_context
57
+ refund_response = @plugin.get_refund_info @pm.kb_account_id, kb_payment_id
67
58
  refund_response.amount.should == (-1 * amount_in_cents)
68
- refund_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
59
+ refund_response.status.should == :PROCESSED
69
60
 
70
61
  # Try another payment to verify the BAID
71
62
  second_amount_in_cents = 9423
72
63
  second_kb_payment_id = SecureRandom.uuid
73
- payment_response = @plugin.process_payment @pm.kb_account_id, second_kb_payment_id, @pm.kb_payment_method_id, second_amount_in_cents, currency, @call_context
64
+ payment_response = @plugin.process_payment @pm.kb_account_id, second_kb_payment_id, @pm.kb_payment_method_id, second_amount_in_cents, currency
74
65
  payment_response.amount.should == second_amount_in_cents
75
- payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
66
+ payment_response.status.should == :PROCESSED
76
67
 
77
68
  # Check we can refund it as well
78
- refund_response = @plugin.process_refund @pm.kb_account_id, second_kb_payment_id, second_amount_in_cents, currency, @call_context
69
+ refund_response = @plugin.process_refund @pm.kb_account_id, second_kb_payment_id, second_amount_in_cents, currency
79
70
  refund_response.amount.should == second_amount_in_cents
80
- refund_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
71
+ refund_response.status.should == :PROCESSED
81
72
 
82
73
  # it "should be able to create and retrieve payment methods"
83
74
  # This should be in a separate scenario but since it's so hard to create a payment method (need manual intervention),
84
75
  # we can't easily delete it
85
- pms = @plugin.get_payment_methods @pm.kb_account_id, false, @call_context
76
+ pms = @plugin.get_payment_methods @pm.kb_account_id, false
86
77
  pms.size.should == 1
87
78
  pms[0].external_payment_method_id.should == @pm.paypal_express_baid
88
79
 
89
- pm_details = @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id, @call_context)
80
+ pm_details = @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id)
90
81
  pm_details.external_payment_method_id.should == @pm.paypal_express_baid
91
82
 
92
- @plugin.delete_payment_method @pm.kb_account_id, @pm.kb_payment_method_id, @call_context
83
+ @plugin.delete_payment_method @pm.kb_account_id, @pm.kb_payment_method_id
93
84
 
94
- @plugin.get_payment_methods(@pm.kb_account_id, false, @call_context).size.should == 0
95
- lambda { @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id, @call_context) }.should raise_error RuntimeError
85
+ @plugin.get_payment_methods(@pm.kb_account_id, false).size.should == 0
86
+ lambda { @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id) }.should raise_error RuntimeError
96
87
  end
97
88
 
98
89
  private
@@ -112,8 +103,12 @@ Note: you need to log-in with a paypal sandbox account (create one here: https:/
112
103
 
113
104
  # Complete the setup process
114
105
  kb_payment_method_id = SecureRandom.uuid
115
- info = Killbill::Plugin::Model::PaymentMethodPlugin.new nil, nil, [Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, "token", token)], nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
116
- response = @plugin.add_payment_method kb_account_id, kb_payment_method_id, info, true, @call_context
106
+ pm_kv_info = Killbill::Plugin::Model::PaymentMethodKVInfo.new
107
+ pm_kv_info.key = 'token'
108
+ pm_kv_info.value = token
109
+ info = Killbill::Plugin::Model::PaymentMethodPlugin.new
110
+ info.properties = [pm_kv_info]
111
+ response = @plugin.add_payment_method kb_account_id, kb_payment_method_id, info, true
117
112
  response.should be_true
118
113
 
119
114
  # Verify our table directly
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-paypal-express
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.17
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: killbill
@@ -17,13 +17,13 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.19
20
+ version: 1.1.2
21
21
  none: false
22
22
  requirement: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.19
26
+ version: 1.1.2
27
27
  none: false
28
28
  prerelease: false
29
29
  type: :runtime
@@ -165,6 +165,7 @@ files:
165
165
  - ".travis.yml"
166
166
  - Gemfile
167
167
  - Jarfile
168
+ - NEWS
168
169
  - README.md
169
170
  - Rakefile
170
171
  - VERSION