activemerchant 1.42.4 → 1.42.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ module Integrations #:nodoc:
6
+ module Doku
7
+ class Notification < ActiveMerchant::Billing::Integrations::Notification
8
+
9
+ self.production_ips = ['103.10.128.11', '103.10.128.14']
10
+
11
+ def complete?
12
+ status.present?
13
+ end
14
+
15
+ def item_id
16
+ params['TRANSIDMERCHANT']
17
+ end
18
+
19
+ def gross
20
+ params['AMOUNT']
21
+ end
22
+
23
+ def status
24
+ case params['RESULT']
25
+ when 'Success'
26
+ 'Completed'
27
+ when 'Fail'
28
+ 'Failed'
29
+ end
30
+ end
31
+
32
+ def currency
33
+ 'IDR'
34
+ end
35
+
36
+ def words
37
+ params['WORDS']
38
+ end
39
+
40
+ def type
41
+ if words && params['STOREID']
42
+ 'verify'
43
+ elsif status
44
+ 'notify'
45
+ end
46
+ end
47
+
48
+ # no unique ID is generated by Doku at any point in the process,
49
+ # so use the same as the original order number.
50
+ def transaction_id
51
+ params['TRANSIDMERCHANT']
52
+ end
53
+
54
+ def acknowledge(authcode = nil)
55
+ case type
56
+ when 'verify'
57
+ words == Digest::SHA1.hexdigest("#{gross}#{@options[:credential2]}#{item_id}")
58
+ when 'notify'
59
+ true
60
+ else
61
+ false
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module Doku
5
+ class Return < ActiveMerchant::Billing::Integrations::Return
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,13 +7,7 @@ module ActiveMerchant #:nodoc:
7
7
  module Moneybookers
8
8
  class Notification < ActiveMerchant::Billing::Integrations::Notification
9
9
 
10
- def initialize(data, options)
11
- if options[:credential2].nil?
12
- raise ArgumentError, "You need to provide the md5 secret as the option :credential2 to verify that the notification originated from Moneybookers"
13
- end
14
- super
15
- end
16
-
10
+
17
11
  def complete?
18
12
  status == 'Completed'
19
13
  end
@@ -119,7 +113,7 @@ module ActiveMerchant #:nodoc:
119
113
  # ... log possible hacking attempt ...
120
114
  # end
121
115
  def acknowledge(authcode = nil)
122
- fields = [merchant_id, item_id, Digest::MD5.hexdigest(secret).upcase, merchant_amount, merchant_currency, status_code].join
116
+ fields = [merchant_id, item_id, Digest::MD5.hexdigest(secret.to_s).upcase, merchant_amount, merchant_currency, status_code].join
123
117
  md5sig == Digest::MD5.hexdigest(fields).upcase
124
118
  end
125
119
  end
@@ -1,25 +1,25 @@
1
1
  module ActiveMerchant #:nodoc:
2
2
  module Billing #:nodoc:
3
3
  module Integrations #:nodoc:
4
- module TwoCheckout
4
+ module TwoCheckout
5
5
  autoload 'Helper', File.dirname(__FILE__) + '/two_checkout/helper'
6
6
  autoload 'Return', File.dirname(__FILE__) + '/two_checkout/return'
7
7
  autoload 'Notification', File.dirname(__FILE__) + '/two_checkout/notification'
8
-
8
+
9
9
  mattr_accessor :payment_routine
10
10
  self.payment_routine = :single_page
11
-
11
+
12
12
  def self.service_url
13
13
  case self.payment_routine
14
14
  when :multi_page
15
- 'https://www.2checkout.com/checkout/purchase'
15
+ 'https://www.2checkout.com/checkout/purchase'
16
16
  when :single_page
17
17
  'https://www.2checkout.com/checkout/spurchase'
18
18
  else
19
19
  raise StandardError, "Integration payment routine set to an invalid value: #{self.payment_routine}"
20
20
  end
21
21
  end
22
-
22
+
23
23
  def self.service_url=(service_url)
24
24
  # Note: do not use this method, it is here for backward compatibility
25
25
  # Use the payment_routine method to change service_url
@@ -29,14 +29,14 @@ module ActiveMerchant #:nodoc:
29
29
  self.payment_routine = :multi_page
30
30
  end
31
31
  end
32
-
33
-
32
+
33
+
34
34
  def self.notification(post, options = {})
35
- Notification.new(post)
36
- end
37
-
35
+ Notification.new(post, options)
36
+ end
37
+
38
38
  def self.return(query_string, options = {})
39
- Return.new(query_string)
39
+ Return.new(query_string, options)
40
40
  end
41
41
  end
42
42
  end
@@ -5,8 +5,6 @@ module ActiveMerchant #:nodoc:
5
5
  class Helper < ActiveMerchant::Billing::Integrations::Helper
6
6
  def initialize(order, account, options = {})
7
7
  super
8
- add_field('fixed', 'Y')
9
-
10
8
  if ActiveMerchant::Billing::Base.integration_mode == :test || options[:test]
11
9
  add_field('demo', 'Y')
12
10
  end
@@ -16,38 +14,52 @@ module ActiveMerchant #:nodoc:
16
14
  mapping :account, 'sid'
17
15
 
18
16
  # The total amount to be billed, in decimal form, without a currency symbol. (8 characters, decimal, 2 characters: Example: 99999999.99)
17
+ # This field is only used with the Third Party Cart parameter set.
19
18
  mapping :amount, 'total'
20
19
 
21
- # Pass your order id if you are using Third Part Cart Parameters. (128 characters max)
22
- mapping :order, 'cart_order_id'
20
+ # Pass the sale's currency code.
21
+ mapping :currency, 'currency_code'
23
22
 
24
- # Pass your order id if you are using the Pass Through Products Parameters. (50 characters max)
25
- mapping :invoice, 'merchant_order_id'
23
+ # Pass your order id. (50 characters max)
24
+ mapping :order, 'merchant_order_id'
26
25
 
27
- # Left here for backward compatibility, do not use. The line_item method will add automatically.
28
- mapping :mode, 'mode'
26
+ # Pass your cart identifier if you are using Third Part Cart Parameters. (128 characters max)
27
+ # This value is visible to the buyer and will be listed as the sale's lineitem.
28
+ mapping :invoice, 'cart_order_id'
29
29
 
30
- mapping :customer, :email => 'email',
30
+ mapping :customer,
31
+ :email => 'email',
31
32
  :phone => 'phone'
32
33
 
33
- mapping :billing_address, :city => 'city',
34
+ mapping :billing_address,
35
+ :city => 'city',
34
36
  :address1 => 'street_address',
35
37
  :address2 => 'street_address2',
36
38
  :state => 'state',
37
39
  :zip => 'zip',
38
40
  :country => 'country'
39
41
 
40
- mapping :shipping_address, :city => 'ship_city',
42
+ mapping :shipping_address,
43
+ :name => 'ship_name',
44
+ :city => 'ship_city',
41
45
  :address1 => 'ship_street_address',
46
+ :address2 => 'ship_street_address2',
42
47
  :state => 'ship_state',
43
48
  :zip => 'ship_zip',
44
49
  :country => 'ship_country'
45
50
 
46
- # Does nothing, since we've disabled the Continue Shopping button by using the fixed = Y field
47
- mapping :return_url, 'return_url'
51
+ # Overrides Approved URL for return process redirects
52
+ mapping :return_url, 'x_receipt_link_url'
53
+
54
+ # notifications are sent via static URLs in the Instant Notification Settings of 2Checkout admin
55
+ mapping :notify_url, 'notify_url'
56
+
57
+ # Allow seller to indicate the step of the checkout page
58
+ # Possible values: ‘review-cart’, ‘shipping-information’, ‘shipping-method’, ‘billing-information’ and ‘payment-method’
59
+ mapping :purchase_step, 'purchase_step'
48
60
 
49
- # Approved URL path
50
- mapping :notification_url, 'x_receipt_link_url'
61
+ # Allow referral partners to indicate their shopping cart
62
+ mapping :cart_type, '2co_cart_type'
51
63
 
52
64
  def customer(params = {})
53
65
  add_field(mappings[:customer][:email], params[:email])
@@ -55,8 +67,12 @@ module ActiveMerchant #:nodoc:
55
67
  add_field('card_holder_name', "#{params[:first_name]} #{params[:last_name]}")
56
68
  end
57
69
 
70
+ def shipping_address(params = {})
71
+ super
72
+ add_field(mappings[:shipping_address][:name], "#{params[:first_name]} #{params[:last_name]}")
73
+ end
74
+
58
75
  # Uses Pass Through Product Parameters to pass in lineitems.
59
- # (must mark tangible sales as shipped to settle the transaction)
60
76
  def line_item(params = {})
61
77
  add_field('mode', '2CO')
62
78
  (max_existing_line_item_id = form_fields.keys.map do |key|
@@ -71,8 +87,8 @@ module ActiveMerchant #:nodoc:
71
87
  end
72
88
 
73
89
  # Uses Third Party Cart parameter set to pass in lineitem details.
74
- # (sales settle automatically)
75
- def auto_settle(params = {})
90
+ # You must also specify `service.invoice` when using this method.
91
+ def third_party_cart(params = {})
76
92
  add_field('id_type', '1')
77
93
  (max_existing_line_item_id = form_fields.keys.map do |key|
78
94
  i = key.to_s[/^c_prod_(\d+)/, 1]
@@ -7,105 +7,124 @@ module ActiveMerchant #:nodoc:
7
7
  module Integrations #:nodoc:
8
8
  module TwoCheckout
9
9
  class Notification < ActiveMerchant::Billing::Integrations::Notification
10
- # card_holder_name - Provides the customer’s name.
11
- # city - Provides the customer’s city.
12
- # country - Provides the customer’s country.
13
- # credit_card_processed - This parameter will always be passed back as Y.
14
- # demo - Defines if an order was live, or if the order was a demo order. If the order was a demo, the MD5 hash will fail.
15
- # email - Provides the email address the customer provided when placing the order.
16
- # fixed - This parameter will only be passed back if it was passed into the purchase routine.
17
- # ip_country - Provides the customer’s IP location.
18
- # key - An MD5 hash used to confirm the validity of a sale.
19
- # lang - Customer language
20
- # merchant_order_id - The order ID you had assigned to the order.
21
- # order_number - The 2Checkout order number associated with the order.
22
- # invoice_id - The 2Checkout invoice number.
23
- # pay_method - Provides seller with the customer’s payment method. CC for Credit Card, PPI for PayPal.
24
- # phone - Provides the phone number the customer provided when placing the order.
25
- # ship_name - Provides the ship to name for the order.
26
- # ship_street_address - Provides ship to address.
27
- # ship_street_address2 - Provides more detailed shipping address if this information was provided by the customer.
28
- # ship_city - Provides ship to city.
29
- # ship_state - Provides ship to state.
30
- # ship_zip - Ship Zip
31
-
32
- # Pass Through Products Only
33
- # li_#_name - Name of the corresponding lineitem.
34
- # li_#_quantity - Quantity of the corresponding lineitem.
35
- # li_#_price - Price of the corresponding lineitem.
36
- # li_#_tangible - Specifies if the corresponding li_#_type is a tangible or intangible. ‘Y’ OR ‘N’
37
- # li_#_product_id - ID of the corresponding lineitem.
38
- # li_#_product_description - Description of the corresponding lineitem.
39
- # li_#_recurrence - # WEEK | MONTH | YEAR – always singular.
40
- # li_#_duration - Forever or # WEEK | MONTH | YEAR – always singular, defaults to Forever.
41
- # li_#_startup_fee - Amount in account pricing currency.
42
- # li_#_option_#_name - Name of option. 64 characters max – cannot include '<' or '>'.
43
- # li_#_option_#_value - Name of option. 64 characters max – cannot include '<' or '>'.
44
- # li_#_option_#_surcharge - Amount in account pricing currency.
45
-
46
- #Third Party Cart Only
47
- # cart_order_id - The order ID you had assigned to the order.
48
-
49
- # Allow seller to define default currency (should match 2Checkout account pricing currency)
10
+
11
+ # message_type - Indicates type of message
12
+ # message_description - Human readable description of message_type
13
+ # timestamp - Timestamp of event; format YYYY-MM-DD HH:MM:SS ZZZ
14
+ # md5_hash - UPPERCASE(MD5_ENCRYPTED(sale_id + vendor_id + invoice_id + Secret Word))
15
+ # message_id - This number is incremented for each message sent to a given seller.
16
+ # key_count - Indicates the number of parameters sent in message
17
+ # vendor_id - Seller account number
18
+ # sale_id - 2Checkout sale number
19
+ # sale_date_placed - Date of sale; format YYYY-MM-DD
20
+ # vendor_order_id - Custom order id provided by seller, if available.
21
+ # invoice_id - 2Checkout invoice number; Each recurring sale can have several invoices
22
+ # recurring - recurring=1 if any item on the invoice is a recurring item, 0 otherwise
23
+ # payment_type - Buyer’s payment method (credit card, online check, paypal ec, OR paypal pay later)
24
+ # list_currency - 3-Letter ISO code for seller currency
25
+ # cust_currency - 3-Letter ISO code for buyer currency
26
+ # auth_exp - The date credit authorization will expire; format YYYY-MM-DD
27
+ # invoice_status - Status of a transaction (approved, pending, deposited, or declined)
28
+ # fraud_status - Status of 2Checkout fraud review (pass, fail, or wait); This parameter could be empty.
29
+ # invoice_list_amount - Total in seller pricing currency; format as appropriate to currency=
30
+ # invoice_usd_amount - Total in US Dollars; format with 2 decimal places
31
+ # invoice_cust_amount - Total in buyer currency; format as appropriate to currency=
32
+ # customer_first_name - Buyer’s first name (may not be available on older sales)
33
+ # customer_last_name - Buyer’s last name (may not be available on older sales)
34
+ # customer_name - Buyer's full name (name as it appears on credit card)
35
+ # customer_email - Buyer's email address
36
+ # customer_phone - Buyer's phone number; all but digits stripped out
37
+ # customer_ip - Buyer's IP address at time of sale
38
+ # customer_ip_country - Country of record for buyer's IP address at time of sale
39
+ # bill_street_address - Billing street address
40
+ # bill_street_address2 - Billing street address line 2
41
+ # bill_city - Billing address city
42
+ # bill_state - Billing address state or province
43
+ # bill_postal_code - Billing address postal code
44
+ # bill_country - 3-Letter ISO country code of billing address
45
+ # ship_status - not_shipped, shipped, or empty (if intangible / does not need shipped)
46
+ # ship_tracking_number - Tracking Number as entered in Seller Admin
47
+ # ship_name - Shipping Recipient’s name (as it should appears on shipping label)
48
+ # ship_street_address - Shipping street address
49
+ # ship_street_address2 - Shipping street address line 2
50
+ # ship_city - Shipping address city
51
+ # ship_state - Shipping address state or province
52
+ # ship_postal_code - Shipping address postal code
53
+ # ship_country - 3-Letter ISO country code of shipping address
54
+ # item_count - Indicates how many numbered sets of item parameters to expect
55
+ # item_name_# - Product name
56
+ # item_id_# - Seller product id
57
+ # item_list_amount_# - Total in seller pricing currency; format as appropriate to currency
58
+ # item_usd_amount_# - Total in US Dollars; format with 2 decimal places
59
+ # item_cust_amount_# - Total in buyer currency; format as appropriate to currency
60
+ # item_type_# - Indicates if item is a bill or refund; Value will be bill or refund
61
+ # item_duration_# - Product duration, how long it re-bills for Ex. 1 Year
62
+ # item_recurrence_# - Product recurrence, how often it re-bills Ex. 1 Month
63
+ # item_rec_list_amount_# - Product price; format as appropriate to currency
64
+ # item_rec_status_# - Indicates status of recurring subscription: live, canceled, or completed
65
+ # item_rec_date_next_# - Date of next recurring installment; format YYYY-MM-DD
66
+ # item_rec_install_billed_# - The number of successful recurring installments successfully billed
67
+
68
+ # INS message type
69
+ def type
70
+ params['message_type']
71
+ end
72
+
73
+ # Seller currency sale was placed in
50
74
  def currency
51
- 'USD'
75
+ params['list_currency']
52
76
  end
53
77
 
54
78
  def complete?
55
79
  status == 'Completed'
56
80
  end
57
81
 
58
- # Third Party Cart parameters will return 'card_order_id'
59
- # Pass Through Product parameters will only return 'merchant_order_id'
82
+ # The value passed with 'merchant_order_id' is passed back as 'vendor_order_id'
60
83
  def item_id
61
- if (params['cart_order_id'].nil?)
62
- params['merchant_order_id']
63
- else
64
- params['cart_order_id']
65
- end
84
+ params['vendor_order_id'] || params['merchant_order_id']
66
85
  end
67
86
 
68
87
  # 2Checkout Sale ID
69
88
  def transaction_id
70
- params['order_number']
89
+ params['sale_id'] || params['order_number']
90
+ end
91
+
92
+ # 2Checkout Invoice ID
93
+ def invoice_id
94
+ params['invoice_id']
71
95
  end
72
96
 
73
97
  def received_at
74
- params['']
98
+ params['timestamp']
75
99
  end
76
100
 
77
101
  #Customer Email
78
102
  def payer_email
79
- params['email']
80
- end
81
-
82
- def receiver_email
83
- params['']
103
+ params['customer_email']
84
104
  end
85
105
 
86
106
  # The MD5 Hash
87
107
  def security_key
88
- params['key']
108
+ params['md5_hash'] || params['key']
89
109
  end
90
110
 
91
111
  # The money amount we received in X.2 decimal.
112
+ # passback || INS gross amount for new orders || default INS gross
92
113
  def gross
93
- params['total']
114
+ params['invoice_list_amount'] || params['total'] || params['item_list_amount_1']
94
115
  end
95
116
 
96
- # Was this a test transaction? # Use the hash
97
- # Please note 2Checkout forces the order number computed in the hash to '1' on demo sales.
98
- def test?
99
- params['demo'] == 'Y'
100
- end
101
-
102
- # 2Checkout only returns 'Y' for this parameter. If the sale is not authorized, no passback occurs.
117
+ # Determine status based on parameter set, if the params include a fraud status we know we're being
118
+ # notified of the finalization of an order (an INS message)
119
+ # If the params include 'credit_card_processed' we know we're being notified of a new order being inbound,
120
+ # which we handle in the deferred demo sale scenario.
103
121
  def status
104
- case params['credit_card_processed']
105
- when 'Y'
106
- 'Completed'
107
- else
108
- 'Failed'
122
+ if params['fraud_status'] == 'pass' || params['credit_card_processed'] == 'Y'
123
+ 'Completed'
124
+ elsif params['fraud_status'] == 'wait'
125
+ 'Pending'
126
+ else
127
+ 'Failed'
109
128
  end
110
129
  end
111
130
 
@@ -117,8 +136,14 @@ module ActiveMerchant #:nodoc:
117
136
  # Checks against MD5 Hash
118
137
  def acknowledge(authcode = nil)
119
138
  return false if security_key.blank?
120
-
121
- Digest::MD5.hexdigest("#{secret}#{params['sid']}#{transaction_id}#{gross}").upcase == security_key.upcase
139
+ if ins_message?
140
+ Digest::MD5.hexdigest("#{ transaction_id }#{ params['vendor_id'] }#{ invoice_id }#{ secret }").upcase == security_key.upcase
141
+ elsif passback?
142
+ order_number = params['demo'] == 'Y' ? 1 : params['order_number']
143
+ Digest::MD5.hexdigest("#{ secret }#{ params['sid'] }#{ order_number }#{ gross }").upcase == params['key'].upcase
144
+ else
145
+ false
146
+ end
122
147
  end
123
148
 
124
149
  private
@@ -132,6 +157,13 @@ module ActiveMerchant #:nodoc:
132
157
  end
133
158
  end
134
159
 
160
+ def ins_message?
161
+ params.include? 'message_type'
162
+ end
163
+
164
+ def passback?
165
+ params.include? 'credit_card_processed'
166
+ end
135
167
  end
136
168
  end
137
169
  end