merb_merchant 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +421 -0
- data/CONTRIBUTERS +90 -0
- data/MIT-LICENSE +20 -0
- data/README +131 -0
- data/Rakefile +129 -0
- data/init.rb +3 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/core_ext/delegating_attributes.rb +76 -0
- data/lib/core_ext/hash_ext.rb +35 -0
- data/lib/core_ext/inheritable_attributes.rb +145 -0
- data/lib/core_ext/time_dsl.rb +59 -0
- data/lib/merb_merchant.rb +96 -0
- data/lib/merb_merchant/billing/avs_result.rb +95 -0
- data/lib/merb_merchant/billing/base.rb +71 -0
- data/lib/merb_merchant/billing/check.rb +68 -0
- data/lib/merb_merchant/billing/credit_card.rb +157 -0
- data/lib/merb_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/merb_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/merb_merchant/billing/cvv_result.rb +38 -0
- data/lib/merb_merchant/billing/expiry_date.rb +28 -0
- data/lib/merb_merchant/billing/gateway.rb +162 -0
- data/lib/merb_merchant/billing/gateways.rb +3 -0
- data/lib/merb_merchant/billing/gateways/authorize_net.rb +646 -0
- data/lib/merb_merchant/billing/gateways/authorize_net_cim.rb +702 -0
- data/lib/merb_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/merb_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
- data/lib/merb_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/merb_merchant/billing/gateways/bogus.rb +98 -0
- data/lib/merb_merchant/billing/gateways/braintree.rb +222 -0
- data/lib/merb_merchant/billing/gateways/card_stream.rb +229 -0
- data/lib/merb_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/merb_merchant/billing/gateways/data_cash.rb +595 -0
- data/lib/merb_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/merb_merchant/billing/gateways/eway.rb +272 -0
- data/lib/merb_merchant/billing/gateways/exact.rb +222 -0
- data/lib/merb_merchant/billing/gateways/linkpoint.rb +396 -0
- data/lib/merb_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/merb_merchant/billing/gateways/modern_payments_cim.rb +214 -0
- data/lib/merb_merchant/billing/gateways/moneris.rb +205 -0
- data/lib/merb_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/merb_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/merb_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/merb_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/merb_merchant/billing/gateways/payflow.rb +236 -0
- data/lib/merb_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/merb_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/merb_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/merb_merchant/billing/gateways/payflow_express.rb +138 -0
- data/lib/merb_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/merb_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/merb_merchant/billing/gateways/payment_express.rb +241 -0
- data/lib/merb_merchant/billing/gateways/paypal.rb +108 -0
- data/lib/merb_merchant/billing/gateways/paypal/paypal_common_api.rb +325 -0
- data/lib/merb_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/merb_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/merb_merchant/billing/gateways/paypal_express.rb +130 -0
- data/lib/merb_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/merb_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/merb_merchant/billing/gateways/protx.rb +284 -0
- data/lib/merb_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/merb_merchant/billing/gateways/psl_card.rb +306 -0
- data/lib/merb_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/merb_merchant/billing/gateways/realex.rb +200 -0
- data/lib/merb_merchant/billing/gateways/sage.rb +146 -0
- data/lib/merb_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/merb_merchant/billing/gateways/sage/sage_core.rb +110 -0
- data/lib/merb_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/merb_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/merb_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/merb_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/merb_merchant/billing/gateways/skip_jack.rb +439 -0
- data/lib/merb_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/merb_merchant/billing/gateways/trust_commerce.rb +418 -0
- data/lib/merb_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/merb_merchant/billing/gateways/verifi.rb +228 -0
- data/lib/merb_merchant/billing/gateways/viaklix.rb +165 -0
- data/lib/merb_merchant/billing/gateways/wirecard.rb +305 -0
- data/lib/merb_merchant/billing/integrations.rb +22 -0
- data/lib/merb_merchant/billing/integrations/action_view_helper.rb +79 -0
- data/lib/merb_merchant/billing/integrations/bogus.rb +29 -0
- data/lib/merb_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/merb_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/merb_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/merb_merchant/billing/integrations/chronopay.rb +29 -0
- data/lib/merb_merchant/billing/integrations/chronopay/helper.rb +81 -0
- data/lib/merb_merchant/billing/integrations/chronopay/notification.rb +156 -0
- data/lib/merb_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/merb_merchant/billing/integrations/gestpay.rb +32 -0
- data/lib/merb_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/merb_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/merb_merchant/billing/integrations/gestpay/notification.rb +83 -0
- data/lib/merb_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/merb_merchant/billing/integrations/helper.rb +93 -0
- data/lib/merb_merchant/billing/integrations/hi_trust.rb +26 -0
- data/lib/merb_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/merb_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/merb_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/merb_merchant/billing/integrations/nochex.rb +101 -0
- data/lib/merb_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/merb_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/merb_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/merb_merchant/billing/integrations/notification.rb +62 -0
- data/lib/merb_merchant/billing/integrations/paypal.rb +54 -0
- data/lib/merb_merchant/billing/integrations/paypal/helper.rb +118 -0
- data/lib/merb_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/merb_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/merb_merchant/billing/integrations/quickpay.rb +25 -0
- data/lib/merb_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/merb_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/merb_merchant/billing/integrations/return.rb +35 -0
- data/lib/merb_merchant/billing/integrations/two_checkout.rb +30 -0
- data/lib/merb_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/merb_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/merb_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/merb_merchant/billing/response.rb +32 -0
- data/lib/merb_merchant/lib/country.rb +298 -0
- data/lib/merb_merchant/lib/error.rb +4 -0
- data/lib/merb_merchant/lib/inflector.rb +69 -0
- data/lib/merb_merchant/lib/post_data.rb +22 -0
- data/lib/merb_merchant/lib/posts_data.rb +109 -0
- data/lib/merb_merchant/lib/requires_parameters.rb +16 -0
- data/lib/merb_merchant/lib/utils.rb +18 -0
- data/lib/merb_merchant/lib/validateable.rb +76 -0
- data/lib/support/gateway_support.rb +57 -0
- data/lib/tasks/cia.rb +90 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/extra/binding_of_caller.rb +80 -0
- data/test/extra/breakpoint.rb +547 -0
- data/test/fixtures.yml +317 -0
- data/test/remote/gateways/remote_authorize_net_cim_test.rb +459 -0
- data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
- data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
- data/test/remote/gateways/remote_beanstream_test.rb +150 -0
- data/test/remote/gateways/remote_braintree_test.rb +154 -0
- data/test/remote/gateways/remote_card_stream_test.rb +148 -0
- data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
- data/test/remote/gateways/remote_data_cash_test.rb +357 -0
- data/test/remote/gateways/remote_efsnet_test.rb +81 -0
- data/test/remote/gateways/remote_eway_test.rb +74 -0
- data/test/remote/gateways/remote_exact_test.rb +60 -0
- data/test/remote/gateways/remote_linkpoint_test.rb +112 -0
- data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
- data/test/remote/gateways/remote_modern_payments_test.rb +43 -0
- data/test/remote/gateways/remote_moneris_test.rb +82 -0
- data/test/remote/gateways/remote_net_registry_test.rb +85 -0
- data/test/remote/gateways/remote_netbilling_test.rb +70 -0
- data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
- data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
- data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
- data/test/remote/gateways/remote_payflow_test.rb +237 -0
- data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
- data/test/remote/gateways/remote_payment_express_test.rb +126 -0
- data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
- data/test/remote/gateways/remote_paypal_test.rb +167 -0
- data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
- data/test/remote/gateways/remote_protx_test.rb +184 -0
- data/test/remote/gateways/remote_psigate_test.rb +50 -0
- data/test/remote/gateways/remote_psl_card_test.rb +125 -0
- data/test/remote/gateways/remote_quickpay_test.rb +190 -0
- data/test/remote/gateways/remote_realex_test.rb +224 -0
- data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
- data/test/remote/gateways/remote_sage_test.rb +87 -0
- data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
- data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
- data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
- data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
- data/test/remote/gateways/remote_skipjack_test.rb +105 -0
- data/test/remote/gateways/remote_trans_first_test.rb +34 -0
- data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
- data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
- data/test/remote/gateways/remote_verifi_test.rb +107 -0
- data/test/remote/gateways/remote_viaklix_test.rb +43 -0
- data/test/remote/gateways/remote_wirecard_test.rb +77 -0
- data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
- data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
- data/test/test_helper.rb +208 -0
- data/test/unit/avs_result_test.rb +59 -0
- data/test/unit/base_test.rb +55 -0
- data/test/unit/check_test.rb +88 -0
- data/test/unit/country_code_test.rb +33 -0
- data/test/unit/country_test.rb +64 -0
- data/test/unit/credit_card_formatting_test.rb +19 -0
- data/test/unit/credit_card_methods_test.rb +170 -0
- data/test/unit/credit_card_test.rb +311 -0
- data/test/unit/cvv_result_test.rb +33 -0
- data/test/unit/expiry_date_test.rb +21 -0
- data/test/unit/gateways/authorize_net_cim_test.rb +638 -0
- data/test/unit/gateways/authorize_net_test.rb +290 -0
- data/test/unit/gateways/beanstream_interac_test.rb +51 -0
- data/test/unit/gateways/beanstream_test.rb +108 -0
- data/test/unit/gateways/bogus_test.rb +46 -0
- data/test/unit/gateways/braintree_test.rb +116 -0
- data/test/unit/gateways/card_stream_test.rb +91 -0
- data/test/unit/gateways/cyber_source_test.rb +188 -0
- data/test/unit/gateways/data_cash_test.rb +132 -0
- data/test/unit/gateways/efsnet_test.rb +124 -0
- data/test/unit/gateways/eway_test.rb +118 -0
- data/test/unit/gateways/exact_test.rb +156 -0
- data/test/unit/gateways/gateway_test.rb +48 -0
- data/test/unit/gateways/linkpoint_test.rb +167 -0
- data/test/unit/gateways/modern_payments_cim_test.rb +171 -0
- data/test/unit/gateways/moneris_test.rb +158 -0
- data/test/unit/gateways/net_registry_test.rb +416 -0
- data/test/unit/gateways/netbilling_test.rb +54 -0
- data/test/unit/gateways/pay_junction_test.rb +123 -0
- data/test/unit/gateways/pay_secure_test.rb +71 -0
- data/test/unit/gateways/payflow_express_test.rb +173 -0
- data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
- data/test/unit/gateways/payflow_test.rb +305 -0
- data/test/unit/gateways/payflow_uk_test.rb +30 -0
- data/test/unit/gateways/payment_express_test.rb +195 -0
- data/test/unit/gateways/paypal_express_test.rb +382 -0
- data/test/unit/gateways/paypal_test.rb +520 -0
- data/test/unit/gateways/plugnpay_test.rb +86 -0
- data/test/unit/gateways/protx_test.rb +122 -0
- data/test/unit/gateways/psigate_test.rb +169 -0
- data/test/unit/gateways/psl_card_test.rb +64 -0
- data/test/unit/gateways/quickpay_test.rb +112 -0
- data/test/unit/gateways/realex_test.rb +151 -0
- data/test/unit/gateways/sage_bankcard_test.rb +162 -0
- data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
- data/test/unit/gateways/secure_pay_au_test.rb +207 -0
- data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
- data/test/unit/gateways/secure_pay_test.rb +87 -0
- data/test/unit/gateways/skip_jack_test.rb +133 -0
- data/test/unit/gateways/trans_first_test.rb +112 -0
- data/test/unit/gateways/trust_commerce_test.rb +90 -0
- data/test/unit/gateways/usa_epay_test.rb +128 -0
- data/test/unit/gateways/verifi_test.rb +96 -0
- data/test/unit/gateways/viaklix_test.rb +78 -0
- data/test/unit/gateways/wirecard_test.rb +232 -0
- data/test/unit/generators/test_gateway_generator.rb +46 -0
- data/test/unit/generators/test_generator_helper.rb +20 -0
- data/test/unit/generators/test_integration_generator.rb +53 -0
- data/test/unit/integrations/action_view_helper_test.rb +50 -0
- data/test/unit/integrations/bogus_module_test.rb +20 -0
- data/test/unit/integrations/chronopay_module_test.rb +13 -0
- data/test/unit/integrations/gestpay_module_test.rb +14 -0
- data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
- data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
- data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
- data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
- data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
- data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
- data/test/unit/integrations/helpers/quickpay_helper_test.rb +40 -0
- data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
- data/test/unit/integrations/hi_trust_module_test.rb +13 -0
- data/test/unit/integrations/nochex_module_test.rb +13 -0
- data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
- data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
- data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
- data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
- data/test/unit/integrations/notifications/notification_test.rb +54 -0
- data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
- data/test/unit/integrations/notifications/quickpay_notification_test.rb +69 -0
- data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
- data/test/unit/integrations/paypal_module_test.rb +28 -0
- data/test/unit/integrations/quickpay_module_test.rb +9 -0
- data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
- data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
- data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
- data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
- data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
- data/test/unit/integrations/returns/return_test.rb +11 -0
- data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
- data/test/unit/integrations/two_checkout_module_test.rb +13 -0
- data/test/unit/post_data_test.rb +55 -0
- data/test/unit/posts_data_test.rb +100 -0
- data/test/unit/response_test.rb +28 -0
- data/test/unit/utils_test.rb +7 -0
- data/test/unit/validateable_test.rb +60 -0
- metadata +379 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/modern_payments_cim'
|
2
|
+
|
3
|
+
module MerbMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
class ModernPaymentsGateway < Gateway
|
6
|
+
self.supported_countries = ModernPaymentsCimGateway.supported_countries
|
7
|
+
self.supported_cardtypes = ModernPaymentsCimGateway.supported_cardtypes
|
8
|
+
self.homepage_url = ModernPaymentsCimGateway.homepage_url
|
9
|
+
self.display_name = ModernPaymentsCimGateway.display_name
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
requires!(options, :login, :password)
|
13
|
+
@options = options
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def purchase(money, credit_card, options = {})
|
18
|
+
customer_response = cim.create_customer(options)
|
19
|
+
return customer_response unless customer_response.success?
|
20
|
+
|
21
|
+
customer_id = customer_response.params["create_customer_result"]
|
22
|
+
|
23
|
+
card_response = cim.modify_customer_credit_card(customer_id, credit_card)
|
24
|
+
return card_response unless card_response.success?
|
25
|
+
|
26
|
+
cim.authorize_credit_card_payment(customer_id, money)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def cim
|
31
|
+
@cim ||= ModernPaymentsCimGateway.new(@options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,214 @@
|
|
1
|
+
module MerbMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class ModernPaymentsCimGateway < Gateway #:nodoc:
|
4
|
+
TEST_URL = "https://secure.modpay.com/netservices/test/ModpayTest.asmx"
|
5
|
+
LIVE_URL = 'https://secure.modpay.com/ws/modpay.asmx'
|
6
|
+
|
7
|
+
LIVE_XMLNS = "http://secure.modpay.com:81/ws/"
|
8
|
+
TEST_XMLNS = "https://secure.modpay.com/netservices/test/"
|
9
|
+
|
10
|
+
self.supported_countries = ['US']
|
11
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
12
|
+
self.homepage_url = 'http://www.modpay.com'
|
13
|
+
self.display_name = 'Modern Payments'
|
14
|
+
|
15
|
+
SUCCESS_MESSAGE = "Transaction accepted"
|
16
|
+
FAILURE_MESSAGE = "Transaction failed"
|
17
|
+
ERROR_MESSAGE = "Transaction error"
|
18
|
+
|
19
|
+
PAYMENT_METHOD = {
|
20
|
+
:check => 1,
|
21
|
+
:credit_card => 2
|
22
|
+
}
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
requires!(options, :login, :password)
|
26
|
+
@options = options
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_customer(options = {})
|
31
|
+
post = {}
|
32
|
+
add_customer_data(post, options)
|
33
|
+
add_address(post, options)
|
34
|
+
|
35
|
+
commit('CreateCustomer', post)
|
36
|
+
end
|
37
|
+
|
38
|
+
def modify_customer_credit_card(customer_id, credit_card)
|
39
|
+
raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
|
40
|
+
|
41
|
+
post = {}
|
42
|
+
add_customer_id(post, customer_id)
|
43
|
+
add_credit_card(post, credit_card)
|
44
|
+
|
45
|
+
commit('ModifyCustomerCreditCard', post)
|
46
|
+
end
|
47
|
+
|
48
|
+
def authorize_credit_card_payment(customer_id, amount)
|
49
|
+
raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
|
50
|
+
|
51
|
+
post = {}
|
52
|
+
add_customer_id(post, customer_id)
|
53
|
+
add_amount(post, amount)
|
54
|
+
|
55
|
+
commit('AuthorizeCreditCardPayment', post)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_payment(customer_id, amount, options = {})
|
59
|
+
raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
|
60
|
+
|
61
|
+
post = {}
|
62
|
+
add_customer_id(post, customer_id)
|
63
|
+
add_amount(post, amount)
|
64
|
+
add_payment_details(post, options)
|
65
|
+
|
66
|
+
commit('CreatePayment', post)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def add_payment_details(post, options)
|
71
|
+
post[:pmtDate] = (options[:payment_date] || Time.now.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
72
|
+
post[:pmtType] = PAYMENT_METHOD[options[:payment_method] || :credit_card]
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_amount(post, money)
|
76
|
+
post[:pmtAmount] = amount(money)
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_customer_id(post, customer_id)
|
80
|
+
post[:custId] = customer_id
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_customer_data(post, options)
|
84
|
+
post[:acctNum] = options[:customer]
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_address(post, options)
|
88
|
+
address = options[:billing_address] || options[:address] || {}
|
89
|
+
|
90
|
+
if name = address[:name]
|
91
|
+
segments = name.split(' ')
|
92
|
+
post[:lastName] = segments.pop
|
93
|
+
post[:firstName] = segments.join(' ')
|
94
|
+
else
|
95
|
+
post[:firstName] = address[:first_name]
|
96
|
+
post[:lastName] = address[:last_name]
|
97
|
+
end
|
98
|
+
|
99
|
+
post[:address] = address[:address1]
|
100
|
+
post[:city] = address[:city]
|
101
|
+
post[:state] = address[:state]
|
102
|
+
post[:zip] = address[:zip]
|
103
|
+
post[:phone] = address[:phone]
|
104
|
+
post[:fax] = address[:fax]
|
105
|
+
post[:email] = address[:email]
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_credit_card(post, credit_card)
|
109
|
+
post[:ccName] = credit_card.name
|
110
|
+
post[:ccNum] = credit_card.number
|
111
|
+
post[:expMonth] = credit_card.month
|
112
|
+
post[:expYear] = credit_card.year
|
113
|
+
end
|
114
|
+
|
115
|
+
def build_request(action, params)
|
116
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
117
|
+
xml.instruct!
|
118
|
+
xml.tag! 'env:Envelope',
|
119
|
+
{ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
120
|
+
'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
121
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' } do
|
122
|
+
|
123
|
+
xml.tag! 'env:Body' do
|
124
|
+
xml.tag! action, { "xmlns" => xmlns(action) } do
|
125
|
+
xml.tag! "clientId", @options[:login]
|
126
|
+
xml.tag! "clientCode", @options[:password]
|
127
|
+
params.each {|key, value| xml.tag! key, value }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
xml.target!
|
132
|
+
end
|
133
|
+
|
134
|
+
def xmlns(action)
|
135
|
+
if test? && action == 'AuthorizeCreditCardPayment'
|
136
|
+
TEST_XMLNS
|
137
|
+
else
|
138
|
+
LIVE_XMLNS
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def url(action)
|
143
|
+
if test? && action == 'AuthorizeCreditCardPayment'
|
144
|
+
TEST_URL
|
145
|
+
else
|
146
|
+
LIVE_URL
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def commit(action, params)
|
151
|
+
data = ssl_post(url(action), build_request(action, params),
|
152
|
+
{ 'Content-Type' =>'text/xml; charset=utf-8',
|
153
|
+
'SOAPAction' => "#{xmlns(action)}#{action}" }
|
154
|
+
)
|
155
|
+
|
156
|
+
response = parse(action, data)
|
157
|
+
Response.new(successful?(action, response), message_from(action, response), response,
|
158
|
+
:test => test?,
|
159
|
+
:authorization => authorization_from(action, response),
|
160
|
+
:avs_result => { :code => response[:avs_code] }
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
def authorization_from(action, response)
|
165
|
+
response[result_key(action)]
|
166
|
+
end
|
167
|
+
|
168
|
+
def result_key(action)
|
169
|
+
action == "AuthorizeCreditCardPayment" ? :trans_id : "#{MerbMerchant::Inflector.underscore(action)}_result".to_sym
|
170
|
+
end
|
171
|
+
|
172
|
+
def successful?(action, response)
|
173
|
+
response[result_key(action)].to_i > 0
|
174
|
+
end
|
175
|
+
|
176
|
+
def message_from(action, response)
|
177
|
+
if response[:faultcode]
|
178
|
+
ERROR_MESSAGE
|
179
|
+
elsif successful?(action, response)
|
180
|
+
SUCCESS_MESSAGE
|
181
|
+
else
|
182
|
+
FAILURE_MESSAGE
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def parse(action, xml)
|
187
|
+
response = {}
|
188
|
+
response[:action] = action
|
189
|
+
|
190
|
+
xml = REXML::Document.new(xml)
|
191
|
+
if root = REXML::XPath.first(xml, "//#{action}Response")
|
192
|
+
root.elements.to_a.each do |node|
|
193
|
+
parse_element(response, node)
|
194
|
+
end
|
195
|
+
elsif root = REXML::XPath.first(xml, "//soap:Fault")
|
196
|
+
root.elements.to_a.each do |node|
|
197
|
+
response[MerbMerchant::Inflector.underscore(node.name).to_sym] = node.text
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
response
|
202
|
+
end
|
203
|
+
|
204
|
+
def parse_element(response, node)
|
205
|
+
if node.has_elements?
|
206
|
+
node.elements.each{|e| parse_element(response, e) }
|
207
|
+
else
|
208
|
+
response[MerbMerchant::Inflector.underscore(node.name).to_sym] = node.text
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
module MerbMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
|
6
|
+
# To learn more about the Moneris gateway, please contact
|
7
|
+
# eselectplus@moneris.com for a copy of their integration guide. For
|
8
|
+
# information on remote testing, please see "Test Environment Penny Value
|
9
|
+
# Response Table", and "Test Environment eFraud (AVS and CVD) Penny
|
10
|
+
# Response Values", available at Moneris' {eSelect Plus Documentation
|
11
|
+
# Centre}[https://www3.moneris.com/connect/en/documents/index.html].
|
12
|
+
class MonerisGateway < Gateway
|
13
|
+
TEST_URL = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
|
14
|
+
LIVE_URL = 'https://www3.moneris.com/gateway2/servlet/MpgRequest'
|
15
|
+
|
16
|
+
self.supported_countries = ['CA']
|
17
|
+
self.supported_cardtypes = [:visa, :master]
|
18
|
+
self.homepage_url = 'http://www.moneris.com/'
|
19
|
+
self.display_name = 'Moneris'
|
20
|
+
|
21
|
+
# login is your Store ID
|
22
|
+
# password is your API Token
|
23
|
+
def initialize(options = {})
|
24
|
+
requires!(options, :login, :password)
|
25
|
+
@options = { :crypt_type => 7 }.update(options)
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# Referred to as "PreAuth" in the Moneris integration guide, this action
|
30
|
+
# verifies and locks funds on a customer's card, which then must be
|
31
|
+
# captured at a later date.
|
32
|
+
#
|
33
|
+
# Pass in +order_id+ and optionally a +customer+ parameter.
|
34
|
+
def authorize(money, creditcard, options = {})
|
35
|
+
debit_commit 'preauth', money, creditcard, options
|
36
|
+
end
|
37
|
+
|
38
|
+
# This action verifies funding on a customer's card, and readies them for
|
39
|
+
# deposit in a merchant's account.
|
40
|
+
#
|
41
|
+
# Pass in <tt>order_id</tt> and optionally a <tt>customer</tt> parameter
|
42
|
+
def purchase(money, creditcard, options = {})
|
43
|
+
debit_commit 'purchase', money, creditcard, options
|
44
|
+
end
|
45
|
+
|
46
|
+
# This method retrieves locked funds from a customer's account (from a
|
47
|
+
# PreAuth) and prepares them for deposit in a merchant's account.
|
48
|
+
#
|
49
|
+
# Note: Moneris requires both the order_id and the transaction number of
|
50
|
+
# the original authorization. To maintain the same interface as the other
|
51
|
+
# gateways the two numbers are concatenated together with a ; separator as
|
52
|
+
# the authorization number returned by authorization
|
53
|
+
def capture(money, authorization, options = {})
|
54
|
+
commit 'completion', crediting_params(authorization, :comp_amount => amount(money))
|
55
|
+
end
|
56
|
+
|
57
|
+
# Voiding requires the original transaction ID and order ID of some open
|
58
|
+
# transaction. Closed transactions must be refunded. Note that the only
|
59
|
+
# methods which may be voided are +capture+ and +purchase+.
|
60
|
+
#
|
61
|
+
# Concatenate your transaction number and order_id by using a semicolon
|
62
|
+
# (';'). This is to keep the Moneris interface consistent with other
|
63
|
+
# gateways. (See +capture+ for details.)
|
64
|
+
def void(authorization, options = {})
|
65
|
+
commit 'purchasecorrection', crediting_params(authorization)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Performs a refund. This method requires that the original transaction
|
69
|
+
# number and order number be included. Concatenate your transaction
|
70
|
+
# number and order_id by using a semicolon (';'). This is to keep the
|
71
|
+
# Moneris interface consistent with other gateways. (See +capture+ for
|
72
|
+
# details.)
|
73
|
+
def credit(money, authorization, options = {})
|
74
|
+
commit 'refund', crediting_params(authorization, :amount => amount(money))
|
75
|
+
end
|
76
|
+
|
77
|
+
private # :nodoc: all
|
78
|
+
|
79
|
+
def expdate(creditcard)
|
80
|
+
sprintf("%.4i", creditcard.year)[-2..-1] + sprintf("%.2i", creditcard.month)
|
81
|
+
end
|
82
|
+
|
83
|
+
def debit_commit(commit_type, money, creditcard, options)
|
84
|
+
requires!(options, :order_id)
|
85
|
+
commit(commit_type, debit_params(money, creditcard, options))
|
86
|
+
end
|
87
|
+
|
88
|
+
# Common params used amongst the +purchase+ and +authorization+ methods
|
89
|
+
def debit_params(money, creditcard, options = {})
|
90
|
+
{
|
91
|
+
:order_id => options[:order_id],
|
92
|
+
:cust_id => options[:customer],
|
93
|
+
:amount => amount(money),
|
94
|
+
:pan => creditcard.number,
|
95
|
+
:expdate => expdate(creditcard),
|
96
|
+
:crypt_type => options[:crypt_type] || @options[:crypt_type]
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
# Common params used amongst the +credit+, +void+ and +capture+ methods
|
101
|
+
def crediting_params(authorization, options = {})
|
102
|
+
{
|
103
|
+
:txn_number => split_authorization(authorization).first,
|
104
|
+
:order_id => split_authorization(authorization).last,
|
105
|
+
:crypt_type => options[:crypt_type] || @options[:crypt_type]
|
106
|
+
}.merge(options)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Splits an +authorization+ param and retrives the order id and
|
110
|
+
# transaction number in that order.
|
111
|
+
def split_authorization(authorization)
|
112
|
+
if authorization.nil? || authorization.empty? || authorization !~ /;/
|
113
|
+
raise ArgumentError, 'You must include a valid authorization code (e.g. "1234;567")'
|
114
|
+
else
|
115
|
+
authorization.split(';')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def commit(action, parameters = {})
|
120
|
+
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters)))
|
121
|
+
|
122
|
+
Response.new(successful?(response), message_from(response[:message]), response,
|
123
|
+
:test => test?,
|
124
|
+
:authorization => authorization_from(response)
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
|
129
|
+
def authorization_from(response = {})
|
130
|
+
if response[:trans_id] && response[:receipt_id]
|
131
|
+
"#{response[:trans_id]};#{response[:receipt_id]}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Tests for a successful response from Moneris' servers
|
136
|
+
def successful?(response)
|
137
|
+
response[:response_code] &&
|
138
|
+
response[:complete] &&
|
139
|
+
(0..49).include?(response[:response_code].to_i)
|
140
|
+
end
|
141
|
+
|
142
|
+
def parse(xml)
|
143
|
+
response = { :message => "Global Error Receipt", :complete => false }
|
144
|
+
hashify_xml!(xml, response)
|
145
|
+
response
|
146
|
+
end
|
147
|
+
|
148
|
+
def hashify_xml!(xml, response)
|
149
|
+
xml = REXML::Document.new(xml)
|
150
|
+
return if xml.root.nil?
|
151
|
+
xml.elements.each('//receipt/*') do |node|
|
152
|
+
response[MerbMerchant::Inflector.underscore(node.name).to_sym] = normalize(node.text)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def post_data(action, parameters = {})
|
157
|
+
xml = REXML::Document.new
|
158
|
+
root = xml.add_element("request")
|
159
|
+
root.add_element("store_id").text = options[:login]
|
160
|
+
root.add_element("api_token").text = options[:password]
|
161
|
+
transaction = root.add_element(action)
|
162
|
+
|
163
|
+
# Must add the elements in the correct order
|
164
|
+
actions[action].each do |key|
|
165
|
+
transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
|
166
|
+
end
|
167
|
+
|
168
|
+
xml.to_s
|
169
|
+
end
|
170
|
+
|
171
|
+
def message_from(message)
|
172
|
+
return 'Unspecified error' if message.blank?
|
173
|
+
message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
|
174
|
+
end
|
175
|
+
|
176
|
+
# Make a Ruby type out of the response string
|
177
|
+
def normalize(field)
|
178
|
+
case field
|
179
|
+
when "true" then true
|
180
|
+
when "false" then false
|
181
|
+
when '', "null" then nil
|
182
|
+
else field
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def actions
|
187
|
+
{
|
188
|
+
"purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
|
189
|
+
"preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
|
190
|
+
"command" => [:order_id],
|
191
|
+
"refund" => [:order_id, :amount, :txn_number, :crypt_type],
|
192
|
+
"indrefund" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
|
193
|
+
"completion" => [:order_id, :comp_amount, :txn_number, :crypt_type],
|
194
|
+
"purchasecorrection" => [:order_id, :txn_number, :crypt_type],
|
195
|
+
"cavvpurcha" => [:order_id, :cust_id, :amount, :pan, :expdate, :cav],
|
196
|
+
"cavvpreaut" => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
|
197
|
+
"transact" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
|
198
|
+
"Batchcloseall" => [],
|
199
|
+
"opentotals" => [:ecr_number],
|
200
|
+
"batchclose" => [:ecr_number]
|
201
|
+
}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|