killbill-paypal-express 1.6.4 → 1.6.5
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 +4 -4
 - data/Jarfile +5 -5
 - data/NEWS +8 -0
 - data/README.md +3 -0
 - data/VERSION +1 -1
 - data/killbill-paypal-express.gemspec +2 -1
 - data/lib/paypal_express/api.rb +14 -4
 - data/lib/paypal_express/models/paypal_express_response.rb +57 -9
 - data/lib/paypal_express/models/paypal_express_transaction.rb +16 -10
 - data/lib/paypal_express.rb +1 -0
 - data/pom.xml +1 -1
 - data/spec/paypal_express/paypal_express_response_spec.rb +84 -0
 - data/spec/paypal_express/remote/integration_spec.rb +4 -3
 - metadata +20 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e6edd71974c6e3f234a22b6012786d8311d4145e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b0cf73fbec05c8a238d0575a69d870810cb2c436
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2d7de8573d9a997cce9dffd8dc470573f9ec220151722d96c9e44dca6f372652c9b7c135b3c6670d9220deaab3ed635e3dd293607f4458eef09403106c498c31
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 388ed005eef4307c1105621f39d85f8db4f00b30c2e5124c73a77d1a04e2c19b48f3f8f6d8a8608cffcd25c4536fd222c0502e52aacae02cac4c2c0adb81282e
         
     | 
    
        data/Jarfile
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            jar 'com.ning.billing:killbill-api', '0. 
     | 
| 
       2 
     | 
    
         
            -
            jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.6. 
     | 
| 
       3 
     | 
    
         
            -
            jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.6. 
     | 
| 
       4 
     | 
    
         
            -
            jar 'com.ning.billing.plugin:killbill-plugin-api-currency', '0.6. 
     | 
| 
       5 
     | 
    
         
            -
            jar 'com.ning.billing:killbill-util:tests', '0. 
     | 
| 
      
 1 
     | 
    
         
            +
            jar 'com.ning.billing:killbill-api', '0.8.0'
         
     | 
| 
      
 2 
     | 
    
         
            +
            jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.6.3'
         
     | 
| 
      
 3 
     | 
    
         
            +
            jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.6.3'
         
     | 
| 
      
 4 
     | 
    
         
            +
            jar 'com.ning.billing.plugin:killbill-plugin-api-currency', '0.6.3'
         
     | 
| 
      
 5 
     | 
    
         
            +
            jar 'com.ning.billing:killbill-util:tests', '0.8.8'
         
     | 
| 
       6 
6 
     | 
    
         
             
            jar 'javax.servlet:javax.servlet-api', '3.0.1'
         
     | 
    
        data/NEWS
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -6,6 +6,9 @@ killbill-paypal-express-plugin 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            Plugin to use Express Checkout as a gateway.
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
            Release builds are available on [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.ning.killbill.ruby%22%20AND%20a%3A%22paypal-express-plugin%22) with coordinates `com.ning.killbill.ruby:paypal-express-plugin`.
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       9 
12 
     | 
    
         
             
            Usage
         
     | 
| 
       10 
13 
     | 
    
         
             
            -----
         
     | 
| 
       11 
14 
     | 
    
         | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            1.6. 
     | 
| 
      
 1 
     | 
    
         
            +
            1.6.5
         
     | 
| 
         @@ -22,9 +22,10 @@ Gem::Specification.new do |s| 
     | 
|
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
              s.rdoc_options << '--exclude' << '.'
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              s.add_dependency 'killbill', '~>  
     | 
| 
      
 25 
     | 
    
         
            +
              s.add_dependency 'killbill', '~> 2.0.0'
         
     | 
| 
       26 
26 
     | 
    
         
             
              s.add_dependency 'activemerchant', '~> 1.36.0'
         
     | 
| 
       27 
27 
     | 
    
         
             
              s.add_dependency 'activerecord', '~> 3.2.1'
         
     | 
| 
      
 28 
     | 
    
         
            +
              s.add_dependency 'money', '~> 6.0.0'
         
     | 
| 
       28 
29 
     | 
    
         
             
              s.add_dependency 'sinatra', '~> 1.3.4'
         
     | 
| 
       29 
30 
     | 
    
         
             
              if defined?(JRUBY_VERSION)
         
     | 
| 
       30 
31 
     | 
    
         
             
                s.add_dependency 'activerecord-jdbcmysql-adapter', '~> 1.2.9'
         
     | 
    
        data/lib/paypal_express/api.rb
    CHANGED
    
    | 
         @@ -17,7 +17,8 @@ module Killbill::PaypalExpress 
     | 
|
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount, currency, call_context = nil, options = {})
         
     | 
| 
       20 
     | 
    
         
            -
                   
     | 
| 
      
 20 
     | 
    
         
            +
                  # Use Money to compute the amount in cents, as it depends on the currency (1 cent of BTC is 1 Satoshi, not 0.01 BTC)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  amount_in_cents = Money.new_with_amount(amount, currency).cents.to_i
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
                  # If the payment was already made, just return the status
         
     | 
| 
       23 
24 
     | 
    
         
             
                  paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id) rescue nil
         
     | 
| 
         @@ -54,7 +55,8 @@ module Killbill::PaypalExpress 
     | 
|
| 
       54 
55 
     | 
    
         
             
                end
         
     | 
| 
       55 
56 
     | 
    
         | 
| 
       56 
57 
     | 
    
         
             
                def process_refund(kb_account_id, kb_payment_id, amount, currency, call_context = nil, options = {})
         
     | 
| 
       57 
     | 
    
         
            -
                   
     | 
| 
      
 58 
     | 
    
         
            +
                  # Use Money to compute the amount in cents, as it depends on the currency (1 cent of BTC is 1 Satoshi, not 0.01 BTC)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  amount_in_cents = Money.new_with_amount(amount, currency).cents.to_i
         
     | 
| 
       58 
60 
     | 
    
         | 
| 
       59 
61 
     | 
    
         
             
                  # Check for currency conversion
         
     | 
| 
       60 
62 
     | 
    
         
             
                  actual_amount, actual_currency = convert_amount_currency_if_required(amount_in_cents, currency, kb_payment_id)
         
     | 
| 
         @@ -74,11 +76,11 @@ module Killbill::PaypalExpress 
     | 
|
| 
       74 
76 
     | 
    
         
             
                end
         
     | 
| 
       75 
77 
     | 
    
         | 
| 
       76 
78 
     | 
    
         
             
                def get_refund_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
         
     | 
| 
       77 
     | 
    
         
            -
                   
     | 
| 
      
 79 
     | 
    
         
            +
                  paypal_express_transactions = PaypalExpressTransaction.refunds_from_kb_payment_id(kb_payment_id)
         
     | 
| 
       78 
80 
     | 
    
         | 
| 
       79 
81 
     | 
    
         
             
                  # We could also re-fetch it via: @gateway.transaction_details(transaction_id)
         
     | 
| 
       80 
82 
     | 
    
         
             
                  # but we would need to reconstruct the refund_info object
         
     | 
| 
       81 
     | 
    
         
            -
                   
     | 
| 
      
 83 
     | 
    
         
            +
                  paypal_express_transactions.map { |t| t.paypal_express_response.to_refund_response }
         
     | 
| 
       82 
84 
     | 
    
         
             
                end
         
     | 
| 
       83 
85 
     | 
    
         | 
| 
       84 
86 
     | 
    
         
             
                def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default = false, call_context = nil, options = {})
         
     | 
| 
         @@ -173,6 +175,14 @@ module Killbill::PaypalExpress 
     | 
|
| 
       173 
175 
     | 
    
         
             
                  end
         
     | 
| 
       174 
176 
     | 
    
         
             
                end
         
     | 
| 
       175 
177 
     | 
    
         | 
| 
      
 178 
     | 
    
         
            +
                def search_payments(search_key, offset = 0, limit = 100, call_context = nil, options = {})
         
     | 
| 
      
 179 
     | 
    
         
            +
                  PaypalExpressResponse.search(search_key, offset, limit, :payment)
         
     | 
| 
      
 180 
     | 
    
         
            +
                end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                def search_refunds(search_key, offset = 0, limit = 100, call_context = nil, options = {})
         
     | 
| 
      
 183 
     | 
    
         
            +
                  PaypalExpressResponse.search(search_key, offset, limit, :refund)
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
       176 
186 
     | 
    
         
             
                def search_payment_methods(search_key, offset = 0, limit = 100, call_context = nil, options = {})
         
     | 
| 
       177 
187 
     | 
    
         
             
                  PaypalExpressPaymentMethod.search(search_key, offset, limit)
         
     | 
| 
       178 
188 
     | 
    
         
             
                end
         
     | 
| 
         @@ -125,12 +125,57 @@ module Killbill::PaypalExpress 
     | 
|
| 
       125 
125 
     | 
    
         
             
                  to_killbill_response :refund
         
     | 
| 
       126 
126 
     | 
    
         
             
                end
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
      
 128 
     | 
    
         
            +
                # VisibleForTesting
         
     | 
| 
      
 129 
     | 
    
         
            +
                def self.search_query(api_call, search_key, offset = nil, limit = nil)
         
     | 
| 
      
 130 
     | 
    
         
            +
                  t = self.arel_table
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                  # Exact matches only
         
     | 
| 
      
 133 
     | 
    
         
            +
                  where_clause =     t[:authorization].eq(search_key)
         
     | 
| 
      
 134 
     | 
    
         
            +
                                 .or(t[:billing_agreement_id].eq(search_key))
         
     | 
| 
      
 135 
     | 
    
         
            +
                                 .or(t[:payment_info_transactionid].eq(search_key))
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                  # Only search successful payments and refunds
         
     | 
| 
      
 138 
     | 
    
         
            +
                  where_clause = where_clause.and(t[:api_call].eq(api_call))
         
     | 
| 
      
 139 
     | 
    
         
            +
                                             .and(t[:success].eq(true))
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                  query = t.where(where_clause)
         
     | 
| 
      
 142 
     | 
    
         
            +
                           .order(t[:id])
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                  if offset.blank? and limit.blank?
         
     | 
| 
      
 145 
     | 
    
         
            +
                    # true is for count distinct
         
     | 
| 
      
 146 
     | 
    
         
            +
                    query.project(t[:id].count(true))
         
     | 
| 
      
 147 
     | 
    
         
            +
                  else
         
     | 
| 
      
 148 
     | 
    
         
            +
                    query.skip(offset) unless offset.blank?
         
     | 
| 
      
 149 
     | 
    
         
            +
                    query.take(limit) unless limit.blank?
         
     | 
| 
      
 150 
     | 
    
         
            +
                    query.project(t[Arel.star])
         
     | 
| 
      
 151 
     | 
    
         
            +
                    # Not chainable
         
     | 
| 
      
 152 
     | 
    
         
            +
                    query.distinct
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                  query
         
     | 
| 
      
 155 
     | 
    
         
            +
                end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                def self.search(search_key, offset = 0, limit = 100, type = :payment)
         
     | 
| 
      
 158 
     | 
    
         
            +
                  api_call = type == :payment ? 'charge' : 'refund'
         
     | 
| 
      
 159 
     | 
    
         
            +
                  pagination = Killbill::Plugin::Model::Pagination.new
         
     | 
| 
      
 160 
     | 
    
         
            +
                  pagination.current_offset = offset
         
     | 
| 
      
 161 
     | 
    
         
            +
                  pagination.total_nb_records = self.count_by_sql(self.search_query(api_call, search_key))
         
     | 
| 
      
 162 
     | 
    
         
            +
                  pagination.max_nb_records = self.where(:api_call => api_call, :success => true).count
         
     | 
| 
      
 163 
     | 
    
         
            +
                  pagination.next_offset = (!pagination.total_nb_records.nil? && offset + limit >= pagination.total_nb_records) ? nil : offset + limit
         
     | 
| 
      
 164 
     | 
    
         
            +
                  # Reduce the limit if the specified value is larger than the number of records
         
     | 
| 
      
 165 
     | 
    
         
            +
                  actual_limit = [pagination.max_nb_records, limit].min
         
     | 
| 
      
 166 
     | 
    
         
            +
                  pagination.iterator = StreamyResultSet.new(actual_limit) do |offset,limit|
         
     | 
| 
      
 167 
     | 
    
         
            +
                    self.find_by_sql(self.search_query(api_call, search_key, offset, limit))
         
     | 
| 
      
 168 
     | 
    
         
            +
                        .map { |x| type == :payment ? x.to_payment_response : x.to_refund_response }
         
     | 
| 
      
 169 
     | 
    
         
            +
                  end
         
     | 
| 
      
 170 
     | 
    
         
            +
                  pagination
         
     | 
| 
      
 171 
     | 
    
         
            +
                end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
       128 
173 
     | 
    
         
             
                private
         
     | 
| 
       129 
174 
     | 
    
         | 
| 
       130 
175 
     | 
    
         
             
                def to_killbill_response(type)
         
     | 
| 
       131 
176 
     | 
    
         
             
                  if paypal_express_transaction.nil?
         
     | 
| 
       132 
     | 
    
         
            -
                    # payment_info_grossamount  
     | 
| 
       133 
     | 
    
         
            -
                    amount_in_cents =  
     | 
| 
      
 177 
     | 
    
         
            +
                    # payment_info_grossamount may have a value but we cannot convert it to cents since we don't have the currency
         
     | 
| 
      
 178 
     | 
    
         
            +
                    amount_in_cents = nil
         
     | 
| 
       134 
179 
     | 
    
         
             
                    currency = nil
         
     | 
| 
       135 
180 
     | 
    
         
             
                    created_date = created_at
         
     | 
| 
       136 
181 
     | 
    
         
             
                    first_payment_reference_id = nil
         
     | 
| 
         @@ -139,8 +184,8 @@ module Killbill::PaypalExpress 
     | 
|
| 
       139 
184 
     | 
    
         
             
                    amount_in_cents = paypal_express_transaction.amount_in_cents
         
     | 
| 
       140 
185 
     | 
    
         
             
                    currency = paypal_express_transaction.currency
         
     | 
| 
       141 
186 
     | 
    
         
             
                    created_date = paypal_express_transaction.created_at
         
     | 
| 
       142 
     | 
    
         
            -
                     
     | 
| 
       143 
     | 
    
         
            -
                     
     | 
| 
      
 187 
     | 
    
         
            +
                    first_reference_id = paypal_express_transaction.paypal_express_txn_id
         
     | 
| 
      
 188 
     | 
    
         
            +
                    second_reference_id = nil
         
     | 
| 
       144 
189 
     | 
    
         
             
                  end
         
     | 
| 
       145 
190 
     | 
    
         | 
| 
       146 
191 
     | 
    
         
             
                  effective_date = created_date
         
     | 
| 
         @@ -149,26 +194,29 @@ module Killbill::PaypalExpress 
     | 
|
| 
       149 
194 
     | 
    
         | 
| 
       150 
195 
     | 
    
         
             
                  if type == :payment
         
     | 
| 
       151 
196 
     | 
    
         
             
                    p_info_plugin = Killbill::Plugin::Model::PaymentInfoPlugin.new
         
     | 
| 
       152 
     | 
    
         
            -
                    p_info_plugin. 
     | 
| 
      
 197 
     | 
    
         
            +
                    p_info_plugin.kb_payment_id = kb_payment_id
         
     | 
| 
      
 198 
     | 
    
         
            +
                    p_info_plugin.amount = Money.new(amount_in_cents, currency).to_d if currency
         
     | 
| 
       153 
199 
     | 
    
         
             
                    p_info_plugin.currency = currency
         
     | 
| 
       154 
200 
     | 
    
         
             
                    p_info_plugin.created_date = created_date
         
     | 
| 
       155 
201 
     | 
    
         
             
                    p_info_plugin.effective_date = effective_date
         
     | 
| 
       156 
202 
     | 
    
         
             
                    p_info_plugin.status = (success ? :PROCESSED : :ERROR)
         
     | 
| 
       157 
203 
     | 
    
         
             
                    p_info_plugin.gateway_error = gateway_error
         
     | 
| 
       158 
204 
     | 
    
         
             
                    p_info_plugin.gateway_error_code = gateway_error_code
         
     | 
| 
       159 
     | 
    
         
            -
                    p_info_plugin.first_payment_reference_id =  
     | 
| 
       160 
     | 
    
         
            -
                    p_info_plugin.second_payment_reference_id =  
     | 
| 
      
 205 
     | 
    
         
            +
                    p_info_plugin.first_payment_reference_id = first_reference_id
         
     | 
| 
      
 206 
     | 
    
         
            +
                    p_info_plugin.second_payment_reference_id = second_reference_id
         
     | 
| 
       161 
207 
     | 
    
         
             
                    p_info_plugin
         
     | 
| 
       162 
208 
     | 
    
         
             
                  else
         
     | 
| 
       163 
209 
     | 
    
         
             
                    r_info_plugin = Killbill::Plugin::Model::RefundInfoPlugin.new
         
     | 
| 
       164 
     | 
    
         
            -
                    r_info_plugin. 
     | 
| 
      
 210 
     | 
    
         
            +
                    r_info_plugin.kb_payment_id = kb_payment_id
         
     | 
| 
      
 211 
     | 
    
         
            +
                    r_info_plugin.amount = Money.new(amount_in_cents, currency).to_d if currency
         
     | 
| 
       165 
212 
     | 
    
         
             
                    r_info_plugin.currency = currency
         
     | 
| 
       166 
213 
     | 
    
         
             
                    r_info_plugin.created_date = created_date
         
     | 
| 
       167 
214 
     | 
    
         
             
                    r_info_plugin.effective_date = effective_date
         
     | 
| 
       168 
215 
     | 
    
         
             
                    r_info_plugin.status = (success ? :PROCESSED : :ERROR)
         
     | 
| 
       169 
216 
     | 
    
         
             
                    r_info_plugin.gateway_error = gateway_error
         
     | 
| 
       170 
217 
     | 
    
         
             
                    r_info_plugin.gateway_error_code = gateway_error_code
         
     | 
| 
       171 
     | 
    
         
            -
                    r_info_plugin. 
     | 
| 
      
 218 
     | 
    
         
            +
                    r_info_plugin.first_refund_reference_id = first_reference_id
         
     | 
| 
      
 219 
     | 
    
         
            +
                    r_info_plugin.second_refund_reference_id = second_reference_id
         
     | 
| 
       172 
220 
     | 
    
         
             
                    r_info_plugin
         
     | 
| 
       173 
221 
     | 
    
         
             
                  end
         
     | 
| 
       174 
222 
     | 
    
         
             
                end
         
     | 
| 
         @@ -8,18 +8,11 @@ module Killbill::PaypalExpress 
     | 
|
| 
       8 
8 
     | 
    
         
             
                                :paypal_express_txn_id
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                def self.from_kb_payment_id(kb_payment_id)
         
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
      
 11 
     | 
    
         
            +
                  transaction_from_kb_payment_id :charge, kb_payment_id, :single
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                def self. 
     | 
| 
       15 
     | 
    
         
            -
                   
     | 
| 
       16 
     | 
    
         
            -
                end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                def self.single_transaction_from_kb_payment_id(api_call, kb_payment_id)
         
     | 
| 
       19 
     | 
    
         
            -
                  paypal_express_transactions = find_all_by_api_call_and_kb_payment_id(api_call, kb_payment_id)
         
     | 
| 
       20 
     | 
    
         
            -
                  raise "Unable to find Paypal Express transaction id for payment #{kb_payment_id}" if paypal_express_transactions.empty?
         
     | 
| 
       21 
     | 
    
         
            -
                  raise "Killbill payment mapping to multiple Paypal Express transactions for payment #{kb_payment_id}" if paypal_express_transactions.size > 1
         
     | 
| 
       22 
     | 
    
         
            -
                  paypal_express_transactions[0]
         
     | 
| 
      
 14 
     | 
    
         
            +
                def self.refunds_from_kb_payment_id(kb_payment_id)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  transaction_from_kb_payment_id :refund, kb_payment_id, :multiple
         
     | 
| 
       23 
16 
     | 
    
         
             
                end
         
     | 
| 
       24 
17 
     | 
    
         | 
| 
       25 
18 
     | 
    
         
             
                def self.find_candidate_transaction_for_refund(kb_payment_id, amount_in_cents)
         
     | 
| 
         @@ -38,5 +31,18 @@ module Killbill::PaypalExpress 
     | 
|
| 
       38 
31 
     | 
    
         | 
| 
       39 
32 
     | 
    
         
             
                  paypal_express_transactions.first
         
     | 
| 
       40 
33 
     | 
    
         
             
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                private
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def self.transaction_from_kb_payment_id(api_call, kb_payment_id, how_many)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  paypal_express_transactions = find_all_by_api_call_and_kb_payment_id(api_call, kb_payment_id)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  raise "Unable to find Paypal Express transaction id for payment #{kb_payment_id}" if paypal_express_transactions.empty?
         
     | 
| 
      
 40 
     | 
    
         
            +
                  if how_many == :single
         
     | 
| 
      
 41 
     | 
    
         
            +
                    raise "Killbill payment mapping to multiple Paypal Express transactions for payment #{kb_payment_id}" if paypal_express_transactions.size > 1
         
     | 
| 
      
 42 
     | 
    
         
            +
                    paypal_express_transactions[0]
         
     | 
| 
      
 43 
     | 
    
         
            +
                  else
         
     | 
| 
      
 44 
     | 
    
         
            +
                    paypal_express_transactions
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
       41 
47 
     | 
    
         
             
              end
         
     | 
| 
       42 
48 
     | 
    
         
             
            end
         
     | 
    
        data/lib/paypal_express.rb
    CHANGED
    
    
    
        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.6. 
     | 
| 
      
 28 
     | 
    
         
            +
                <version>1.6.5</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>
         
     | 
| 
         @@ -0,0 +1,84 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Killbill::PaypalExpress::PaypalExpressResponse do
         
     | 
| 
      
 4 
     | 
    
         
            +
              before :all do
         
     | 
| 
      
 5 
     | 
    
         
            +
                Killbill::PaypalExpress::PaypalExpressResponse.delete_all
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              it 'should generate the right SQL query' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                # Check count query (search query numeric)
         
     | 
| 
      
 10 
     | 
    
         
            +
                expected_query = "SELECT COUNT(DISTINCT \"paypal_express_responses\".\"id\") FROM \"paypal_express_responses\"  WHERE ((\"paypal_express_responses\".\"authorization\" = '1234' OR \"paypal_express_responses\".\"billing_agreement_id\" = '1234') OR \"paypal_express_responses\".\"payment_info_transactionid\" = '1234') AND \"paypal_express_responses\".\"api_call\" = 'charge' AND \"paypal_express_responses\".\"success\" = 't' ORDER BY \"paypal_express_responses\".\"id\""
         
     | 
| 
      
 11 
     | 
    
         
            +
                # Note that Kill Bill will pass a String, even for numeric types
         
     | 
| 
      
 12 
     | 
    
         
            +
                Killbill::PaypalExpress::PaypalExpressResponse.search_query('charge', '1234').to_sql.should == expected_query
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                # Check query with results (search query numeric)
         
     | 
| 
      
 15 
     | 
    
         
            +
                expected_query = "SELECT  DISTINCT \"paypal_express_responses\".* FROM \"paypal_express_responses\"  WHERE ((\"paypal_express_responses\".\"authorization\" = '1234' OR \"paypal_express_responses\".\"billing_agreement_id\" = '1234') OR \"paypal_express_responses\".\"payment_info_transactionid\" = '1234') AND \"paypal_express_responses\".\"api_call\" = 'charge' AND \"paypal_express_responses\".\"success\" = 't' ORDER BY \"paypal_express_responses\".\"id\" LIMIT 10 OFFSET 0"
         
     | 
| 
      
 16 
     | 
    
         
            +
                # Note that Kill Bill will pass a String, even for numeric types
         
     | 
| 
      
 17 
     | 
    
         
            +
                Killbill::PaypalExpress::PaypalExpressResponse.search_query('charge', '1234', 0, 10).to_sql.should == expected_query
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                # Check count query (search query string)
         
     | 
| 
      
 20 
     | 
    
         
            +
                expected_query = "SELECT COUNT(DISTINCT \"paypal_express_responses\".\"id\") FROM \"paypal_express_responses\"  WHERE ((\"paypal_express_responses\".\"authorization\" = 'XXX' OR \"paypal_express_responses\".\"billing_agreement_id\" = 'XXX') OR \"paypal_express_responses\".\"payment_info_transactionid\" = 'XXX') AND \"paypal_express_responses\".\"api_call\" = 'charge' AND \"paypal_express_responses\".\"success\" = 't' ORDER BY \"paypal_express_responses\".\"id\""
         
     | 
| 
      
 21 
     | 
    
         
            +
                Killbill::PaypalExpress::PaypalExpressResponse.search_query('charge', 'XXX').to_sql.should == expected_query
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # Check query with results (search query string)
         
     | 
| 
      
 24 
     | 
    
         
            +
                expected_query = "SELECT  DISTINCT \"paypal_express_responses\".* FROM \"paypal_express_responses\"  WHERE ((\"paypal_express_responses\".\"authorization\" = 'XXX' OR \"paypal_express_responses\".\"billing_agreement_id\" = 'XXX') OR \"paypal_express_responses\".\"payment_info_transactionid\" = 'XXX') AND \"paypal_express_responses\".\"api_call\" = 'charge' AND \"paypal_express_responses\".\"success\" = 't' ORDER BY \"paypal_express_responses\".\"id\" LIMIT 10 OFFSET 0"
         
     | 
| 
      
 25 
     | 
    
         
            +
                Killbill::PaypalExpress::PaypalExpressResponse.search_query('charge', 'XXX', 0, 10).to_sql.should == expected_query
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              it 'should search all fields' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                do_search('foo').size.should == 0
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                pm = Killbill::PaypalExpress::PaypalExpressResponse.create :api_call => 'charge',
         
     | 
| 
      
 32 
     | 
    
         
            +
                                                                           :kb_payment_id => '11-22-33-44',
         
     | 
| 
      
 33 
     | 
    
         
            +
                                                                           :authorization => '55-66-77-88',
         
     | 
| 
      
 34 
     | 
    
         
            +
                                                                           :billing_agreement_id => 38102343,
         
     | 
| 
      
 35 
     | 
    
         
            +
                                                                           :payment_info_transactionid => 'order-id-1',
         
     | 
| 
      
 36 
     | 
    
         
            +
                                                                           :success => true
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                # Wrong api_call
         
     | 
| 
      
 39 
     | 
    
         
            +
                ignored1 = Killbill::PaypalExpress::PaypalExpressResponse.create :api_call => 'add_payment_method',
         
     | 
| 
      
 40 
     | 
    
         
            +
                                                                                 :kb_payment_id => pm.kb_payment_id,
         
     | 
| 
      
 41 
     | 
    
         
            +
                                                                                 :authorization => pm.authorization,
         
     | 
| 
      
 42 
     | 
    
         
            +
                                                                                 :billing_agreement_id => pm.billing_agreement_id,
         
     | 
| 
      
 43 
     | 
    
         
            +
                                                                                 :payment_info_transactionid => pm.payment_info_transactionid,
         
     | 
| 
      
 44 
     | 
    
         
            +
                                                                                 :success => true
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                # Not successful
         
     | 
| 
      
 47 
     | 
    
         
            +
                ignored2 = Killbill::PaypalExpress::PaypalExpressResponse.create :api_call => 'charge',
         
     | 
| 
      
 48 
     | 
    
         
            +
                                                                                 :kb_payment_id => pm.kb_payment_id,
         
     | 
| 
      
 49 
     | 
    
         
            +
                                                                                 :authorization => pm.authorization,
         
     | 
| 
      
 50 
     | 
    
         
            +
                                                                                 :billing_agreement_id => pm.billing_agreement_id,
         
     | 
| 
      
 51 
     | 
    
         
            +
                                                                                 :payment_info_transactionid => pm.payment_info_transactionid,
         
     | 
| 
      
 52 
     | 
    
         
            +
                                                                                 :success => false
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                do_search('foo').size.should == 0
         
     | 
| 
      
 55 
     | 
    
         
            +
                do_search(pm.authorization).size.should == 1
         
     | 
| 
      
 56 
     | 
    
         
            +
                do_search(pm.billing_agreement_id).size.should == 1
         
     | 
| 
      
 57 
     | 
    
         
            +
                do_search(pm.payment_info_transactionid).size.should == 1
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                pm2 = Killbill::PaypalExpress::PaypalExpressResponse.create :api_call => 'charge',
         
     | 
| 
      
 60 
     | 
    
         
            +
                                                                            :kb_payment_id => '11-22-33-44',
         
     | 
| 
      
 61 
     | 
    
         
            +
                                                                            :authorization => '11-22-33-44',
         
     | 
| 
      
 62 
     | 
    
         
            +
                                                                            :billing_agreement_id => pm.billing_agreement_id,
         
     | 
| 
      
 63 
     | 
    
         
            +
                                                                            :payment_info_transactionid => 'order-id-2',
         
     | 
| 
      
 64 
     | 
    
         
            +
                                                                            :success => true
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                do_search('foo').size.should == 0
         
     | 
| 
      
 67 
     | 
    
         
            +
                do_search(pm.authorization).size.should == 1
         
     | 
| 
      
 68 
     | 
    
         
            +
                do_search(pm.billing_agreement_id).size.should == 2
         
     | 
| 
      
 69 
     | 
    
         
            +
                do_search(pm.payment_info_transactionid).size.should == 1
         
     | 
| 
      
 70 
     | 
    
         
            +
                do_search(pm2.authorization).size.should == 1
         
     | 
| 
      
 71 
     | 
    
         
            +
                do_search(pm2.billing_agreement_id).size.should == 2
         
     | 
| 
      
 72 
     | 
    
         
            +
                do_search(pm2.payment_info_transactionid).size.should == 1
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
              private
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              def do_search(search_key)
         
     | 
| 
      
 78 
     | 
    
         
            +
                pagination = Killbill::PaypalExpress::PaypalExpressResponse.search(search_key)
         
     | 
| 
      
 79 
     | 
    
         
            +
                pagination.current_offset.should == 0
         
     | 
| 
      
 80 
     | 
    
         
            +
                results = pagination.iterator.to_a
         
     | 
| 
      
 81 
     | 
    
         
            +
                pagination.total_nb_records.should == results.size
         
     | 
| 
      
 82 
     | 
    
         
            +
                results
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -85,9 +85,10 @@ describe Killbill::PaypalExpress::PaymentPlugin do 
     | 
|
| 
       85 
85 
     | 
    
         
             
                response.success.should be_true
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
87 
     | 
    
         
             
                # Check we can retrieve the refund
         
     | 
| 
       88 
     | 
    
         
            -
                 
     | 
| 
       89 
     | 
    
         
            -
                 
     | 
| 
       90 
     | 
    
         
            -
                 
     | 
| 
      
 88 
     | 
    
         
            +
                refund_responses = @plugin.get_refund_info @pm.kb_account_id, kb_payment_id
         
     | 
| 
      
 89 
     | 
    
         
            +
                refund_responses.size.should == 1
         
     | 
| 
      
 90 
     | 
    
         
            +
                refund_responses[0].amount.should == amount
         
     | 
| 
      
 91 
     | 
    
         
            +
                refund_responses[0].status.should == :PROCESSED
         
     | 
| 
       91 
92 
     | 
    
         | 
| 
       92 
93 
     | 
    
         
             
                # Try another payment to verify the BAID
         
     | 
| 
       93 
94 
     | 
    
         
             
                second_amount = BigDecimal.new("94.23")
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: killbill-paypal-express
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.6. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.6.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Kill Bill core team
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-01- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-01-17 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: killbill
         
     | 
| 
         @@ -16,12 +16,12 @@ dependencies: 
     | 
|
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - ~>
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version:  
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 2.0.0
         
     | 
| 
       20 
20 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       21 
21 
     | 
    
         
             
                requirements:
         
     | 
| 
       22 
22 
     | 
    
         
             
                - - ~>
         
     | 
| 
       23 
23 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       24 
     | 
    
         
            -
                    version:  
     | 
| 
      
 24 
     | 
    
         
            +
                    version: 2.0.0
         
     | 
| 
       25 
25 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       26 
26 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
         @@ -52,6 +52,20 @@ dependencies: 
     | 
|
| 
       52 
52 
     | 
    
         
             
                    version: 3.2.1
         
     | 
| 
       53 
53 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       54 
54 
     | 
    
         
             
              type: :runtime
         
     | 
| 
      
 55 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 56 
     | 
    
         
            +
              name: money
         
     | 
| 
      
 57 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 58 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 59 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 60 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 61 
     | 
    
         
            +
                    version: 6.0.0
         
     | 
| 
      
 62 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 63 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 64 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 65 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 66 
     | 
    
         
            +
                    version: 6.0.0
         
     | 
| 
      
 67 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 68 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
       55 
69 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       56 
70 
     | 
    
         
             
              name: sinatra
         
     | 
| 
       57 
71 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -170,6 +184,7 @@ files: 
     | 
|
| 
       170 
184 
     | 
    
         
             
            - release.sh
         
     | 
| 
       171 
185 
     | 
    
         
             
            - spec/paypal_express/base_plugin_spec.rb
         
     | 
| 
       172 
186 
     | 
    
         
             
            - spec/paypal_express/paypal_express_payment_method_spec.rb
         
     | 
| 
      
 187 
     | 
    
         
            +
            - spec/paypal_express/paypal_express_response_spec.rb
         
     | 
| 
       173 
188 
     | 
    
         
             
            - spec/paypal_express/remote/integration_spec.rb
         
     | 
| 
       174 
189 
     | 
    
         
             
            - spec/paypal_express/streamy_result_set_spec.rb
         
     | 
| 
       175 
190 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
         @@ -202,6 +217,7 @@ summary: Plugin to use Express Checkout as a gateway. 
     | 
|
| 
       202 
217 
     | 
    
         
             
            test_files:
         
     | 
| 
       203 
218 
     | 
    
         
             
            - spec/paypal_express/base_plugin_spec.rb
         
     | 
| 
       204 
219 
     | 
    
         
             
            - spec/paypal_express/paypal_express_payment_method_spec.rb
         
     | 
| 
      
 220 
     | 
    
         
            +
            - spec/paypal_express/paypal_express_response_spec.rb
         
     | 
| 
       205 
221 
     | 
    
         
             
            - spec/paypal_express/remote/integration_spec.rb
         
     | 
| 
       206 
222 
     | 
    
         
             
            - spec/paypal_express/streamy_result_set_spec.rb
         
     | 
| 
       207 
223 
     | 
    
         
             
            - spec/spec_helper.rb
         
     |