johnreitano-activemerchant 1.5.7 → 1.5.8

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.
@@ -54,7 +54,10 @@ module ActiveMerchant #:nodoc:
54
54
  CIM_TRANSACTION_TYPES = {
55
55
  :auth_capture => 'profileTransAuthCapture',
56
56
  :auth_only => 'profileTransAuthOnly',
57
- :capture_only => 'profileTransCaptureOnly'
57
+ :capture_only => 'profileTransCaptureOnly',
58
+ :prior_auth_capture => 'profileTransPriorAuthCapture',
59
+ :refund => 'profileTransRefund',
60
+ :void => 'profileTransVoid'
58
61
  }
59
62
 
60
63
  CIM_VALIDATION_MODES = {
@@ -299,7 +302,7 @@ module ActiveMerchant #:nodoc:
299
302
 
300
303
  # Creates a new payment transaction from an existing customer profile
301
304
  #
302
- # This is what is used to charge a customer whose information you have stored in a Customer Profile.
305
+ # This is what is used to charge, authorize, void, or refund a customer whose information you have stored in a Customer Profile.
303
306
  #
304
307
  # Returns a Response object that contains the result of the transaction in <tt>params['direct_response']</tt>
305
308
  #
@@ -309,14 +312,51 @@ module ActiveMerchant #:nodoc:
309
312
  #
310
313
  # ==== Transaction
311
314
  #
312
- # * <tt>:type</tt> -- The type of transaction. Can be either <tt>:auth_only</tt>, <tt>:capture_only</tt>, or <tt>:auth_capture</tt>. (REQUIRED)
313
- # * <tt>:amount</tt> -- The amount for the tranaction. Formatted with a decimal. For example "4.95" (REQUIRED)
314
- # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (REQUIRED)
315
- # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (REQUIRED)
315
+ # * <tt>:type</tt> -- The type of transaction. Can be either <tt>:auth_only</tt>, <tt>:capture_only</tt>, <tt>:auth_capture</tt>, <tt>:prior_auth_capture</tt>, <tt>:refund</tt> or <tt>:void</tt>. (REQUIRED)
316
+ # * <tt>:amount</tt> -- The amount for the tranaction. Formatted with a decimal. For example "4.95" (CONDITIONAL)
317
+ # - :type == :void (NOT USED)
318
+ # - :type == (:refund, :auth_only, :capture_only, :auth_capture, :prior_auth_capture) (REQUIRED)
319
+ #
320
+ # * <tt>:customer_profile_id</tt> -- The Customer Profile ID of the customer to use in this transaction. (CONDITIONAL)
321
+ # - :type == (:void, :prior_auth_capture) (OPTIONAL)
322
+ # - :type == :refund (CONDITIONAL - required if masked information is not being submitted [see below])
323
+ # - :type == (:auth_only, :capture_only, :auth_capture) (REQUIRED)
324
+ #
325
+ # * <tt>:customer_payment_profile_id</tt> -- The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (CONDITIONAL)
326
+ # - :type == (:void, :prior_auth_capture) (OPTIONAL)
327
+ # - :type == :refund (CONDITIONAL - required if masked information is not being submitted [see below])
328
+ # - :type == (:auth_only, :capture_only, :auth_capture) (REQUIRED)
329
+ #
330
+ # * <tt>:trans_id</tt> -- The payment gateway assigned transaction ID of the original transaction (CONDITIONAL):
331
+ # - :type = (:void, :refund, :prior_auth_capture) (REQUIRED)
332
+ # - :type = (:auth_only, :capture_only, :auth_capture) (NOT USED)
333
+ #
334
+ # * <tt>customer_shipping_address_id</tt> -- Payment gateway assigned ID associated with the customer shipping address (CONDITIONAL)
335
+ # - :type = (:void, :refund) (OPTIONAL)
336
+ # - :type = (:auth_only, :capture_only, :auth_capture) (NOT USED)
337
+ # - :type = (:prior_auth_capture) (OPTIONAL)
338
+ #
339
+ # ==== For :type == :refund only
340
+ # * <tt>:credit_card_number_masked</tt> -- (CONDITIONAL - requied for credit card refunds is :customer_profile_id AND :customer_payment_profile_id are missing)
341
+ # * <tt>:bank_routing_number_masked && :bank_account_number_masked</tt> -- (CONDITIONAL - requied for electronic check refunds is :customer_profile_id AND :customer_payment_profile_id are missing) (NOT ABLE TO TEST - I keep getting "ACH transactions are not accepted by this merchant." when trying to make a payment and, until that's possible I can't refund (wiseleyb@gmail.com))
316
342
  def create_customer_profile_transaction(options)
317
343
  requires!(options, :transaction)
318
- requires!(options[:transaction], :type, :amount, :customer_profile_id, :customer_payment_profile_id)
319
-
344
+ requires!(options[:transaction], :type)
345
+ case options[:transaction][:type]
346
+ when :void
347
+ requires!(options[:transaction], :trans_id)
348
+ when :refund
349
+ requires!(options[:transaction], :trans_id) &&
350
+ (
351
+ (options[:transaction][:customer_profile_id] && options[:transaction][:customer_payment_profile_id]) ||
352
+ options[:transaction][:credit_card_number_masked] ||
353
+ (options[:transaction][:bank_routing_number_masked] && options[:transaction][:bank_account_number_masked])
354
+ )
355
+ when :prior_auth_capture
356
+ requires!(options[:transaction], :amount, :trans_id)
357
+ else
358
+ requires!(options[:transaction], :amount, :customer_profile_id, :customer_payment_profile_id)
359
+ end
320
360
  request = build_request(:create_customer_profile_transaction, options)
321
361
  commit(:create_customer_profile_transaction, request)
322
362
  end
@@ -502,10 +542,37 @@ module ActiveMerchant #:nodoc:
502
542
  xml.tag!('transaction') do
503
543
  xml.tag!(CIM_TRANSACTION_TYPES[transaction[:type]]) do
504
544
  # The amount to be billed to the customer
505
- xml.tag!('amount', transaction[:amount])
506
- xml.tag!('customerProfileId', transaction[:customer_profile_id])
507
- xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
508
- xml.tag!('approvalCode', transaction[:approval_code]) if transaction[:type] == :capture_only
545
+ case transaction[:type]
546
+ when :void
547
+ tag_unless_blank(xml,'customerProfileId', transaction[:customer_profile_id])
548
+ tag_unless_blank(xml,'customerPaymentProfileId', transaction[:customer_payment_profile_id])
549
+ tag_unless_blank(xml,'customerShippingAddressId', transaction[:customer_shipping_address_id])
550
+ xml.tag!('transId', transaction[:trans_id])
551
+ when :refund
552
+ #TODO - add support for all the other options fields
553
+ xml.tag!('amount', transaction[:amount])
554
+ tag_unless_blank(xml, 'customerProfileId', transaction[:customer_profile_id])
555
+ tag_unless_blank(xml, 'customerPaymentProfileId', transaction[:customer_payment_profile_id])
556
+ tag_unless_blank(xml, 'customerShippingAddressId', transaction[:customer_shipping_address_id])
557
+ tag_unless_blank(xml, 'creditCardNumberMasked', transaction[:credit_card_number_masked])
558
+ tag_unless_blank(xml, 'bankRoutingNumberMasked', transaction[:bank_routing_number_masked])
559
+ tag_unless_blank(xml, 'bankAccountNumberMasked', transaction[:bank_account_number_masked])
560
+ add_order(xml, transaction.delete(:order)) if transaction[:order]
561
+ xml.tag!('transId', transaction[:trans_id])
562
+ when :prior_auth_capture
563
+ xml.tag!('amount', transaction[:amount])
564
+ xml.tag!('transId', transaction[:trans_id])
565
+ when :capture_only
566
+ xml.tag!('amount', transaction[:amount])
567
+ xml.tag!('customerProfileId', transaction[:customer_profile_id])
568
+ xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
569
+ add_order(xml, transaction.delete(:order)) if transaction[:order]
570
+ xml.tag!('approvalCode', transaction[:approval_code])
571
+ else
572
+ xml.tag!('amount', transaction[:amount])
573
+ xml.tag!('customerProfileId', transaction[:customer_profile_id])
574
+ xml.tag!('customerPaymentProfileId', transaction[:customer_payment_profile_id])
575
+ end
509
576
  add_order(xml, transaction[:order]) if transaction[:order]
510
577
  end
511
578
  end
@@ -645,9 +712,14 @@ module ActiveMerchant #:nodoc:
645
712
  )
646
713
 
647
714
  response.params['direct_response'] = parse_direct_response(response) if response.params['direct_response']
715
+
648
716
  response
649
717
  end
650
718
 
719
+ def tag_unless_blank(xml, tag_name, data)
720
+ xml.tag!(tag_name, data) unless data.blank? || data.nil?
721
+ end
722
+
651
723
  def parse_direct_response(response)
652
724
  direct_response = {'raw' => response.params['direct_response']}
653
725
  direct_response_fields = response.params['direct_response'].split(',')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnreitano-activemerchant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 7
10
- version: 1.5.7
9
+ - 8
10
+ version: 1.5.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Reitano
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain:
17
17
  - gem-public_cert.pem
18
- date: 2010-07-14 00:00:00 -07:00
18
+ date: 2010-07-27 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency