Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Update PSL Card Gateway to add support for avs and cvv data. remove t…
Browse files Browse the repository at this point in the history
…est_result_from_cc_number.

git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@595 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information
codyfauser committed Jan 25, 2008
1 parent a7df03c commit 733102b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG

* Update PSL Card Gateway to add support for avs and cvv data. remove test_result_from_cc_number. [cody]
* Update PlugNPayGateway to support avs and cvv data. Remove test_result_from_cc_number. [cody]
* Update PaymentExpressGateway to remove test_result_from_cc_number. [cody]
* Update PaySecure to remove test_result_from_cc_number. [cody]
Expand Down
39 changes: 24 additions & 15 deletions lib/active_merchant/billing/gateways/psl_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ module Billing
# directly to the gateway then the appropriate cardholder present or not present message
# type should be used rather than the ‘E’ equivalent.
# -The CV2 / AVS policies are set up with the account settings when signing up for an account
#
#
class PslCardGateway < Gateway
self.money_format = :cents
self.default_currency = 'GBP'
Expand Down Expand Up @@ -66,6 +64,24 @@ class PslCardGateway < Gateway
#taken.
NOMINAL_AMOUNT = 101

AVS_CODE = {
"ALL MATCH" => 'Y',
"SECURITY CODE MATCH ONLY" => 'N',
"ADDRESS MATCH ONLY" => 'Y',
"NO DATA MATCHES" => 'N',
"DATA NOT CHECKED" => 'R',
"SECURITY CHECKS NOT SUPPORTED" => 'X'
}

CVV_CODE = {
"ALL MATCH" => 'M',
"SECURITY CODE MATCH ONLY" => 'M',
"ADDRESS MATCH ONLY" => 'N',
"NO DATA MATCHES" => 'N',
"DATA NOT CHECKED" => 'P',
"SECURITY CHECKS NOT SUPPORTED" => 'X'
}

# Create a new PslCardGateway
#
# The gateway requires that a valid :login be passed in the options hash
Expand Down Expand Up @@ -247,20 +263,13 @@ def parse(body)
# - ActiveMerchant::Billing::Response object
#
def commit(request)
if result = test_result_from_cc_number(request[:CardNumber])
return result
end

result = ssl_post(URL, post_data(request))

@response = parse(result)

success = @response[:ResponseCode] == APPROVED
message = @response[:Message]
response = parse( ssl_post(URL, post_data(request)) )

Response.new(success, message, @response,
:test => test?,
:authorization => @response[:CrossReference]
Response.new(response[:ResponseCode] == APPROVED, response[:Message], response,
:test => test?,
:authorization => response[:CrossReference],
:cvv_result => CVV_CODE[response[:AVSCV2Check]],
:avs_result => { :code => AVS_CODE[response[:AVSCV2Check]] }
)
end

Expand Down
33 changes: 17 additions & 16 deletions test/remote/gateways/remote_psl_card_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
require File.dirname(__FILE__) + '/../../test_helper'

class RemotePslCardTest < Test::Unit::TestCase
# The test results are determined by the amount of the transaction
ACCEPT_AMOUNT = 1000
REFERRED_AMOUNT = 6000
DECLINED_AMOUNT = 11000
KEEP_CARD_AMOUNT = 15000


def setup
@gateway = PslCardGateway.new(fixtures(:psl_card))

Expand All @@ -20,18 +15,24 @@ def setup

@visa = CreditCard.new(fixtures(:psl_visa))
@visa_address = fixtures(:psl_visa_address)

# The test results are determined by the amount of the transaction
@accept_amount = 1000
@referred_amount = 6000
@declined_amount = 11000
@keep_card_amount = 15000
end

def test_successful_visa_purchase
response = @gateway.purchase(ACCEPT_AMOUNT, @visa,
response = @gateway.purchase(@accept_amount, @visa,
:billing_address => @visa_address
)
assert_success response
assert response.test?
end

def test_successful_visa_purchase_specifying_currency
response = @gateway.purchase(ACCEPT_AMOUNT, @visa,
response = @gateway.purchase(@accept_amount, @visa,
:billing_address => @visa_address,
:currency => 'GBP'
)
Expand All @@ -40,39 +41,39 @@ def test_successful_visa_purchase_specifying_currency
end

def test_successful_solo_purchase
response = @gateway.purchase(ACCEPT_AMOUNT, @solo,
response = @gateway.purchase(@accept_amount, @solo,
:billing_address => @solo_address
)
assert_success response
assert response.test?
end

def test_referred_purchase
response = @gateway.purchase(REFERRED_AMOUNT, @uk_maestro,
response = @gateway.purchase(@referred_amount, @uk_maestro,
:billing_address => @uk_maestro_address
)
assert_failure response
assert response.test?
end

def test_declined_purchase
response = @gateway.purchase(DECLINED_AMOUNT, @uk_maestro,
response = @gateway.purchase(@declined_amount, @uk_maestro,
:billing_address => @uk_maestro_address
)
assert_failure response
assert response.test?
end

def test_declined_keep_card_purchase
response = @gateway.purchase(KEEP_CARD_AMOUNT, @uk_maestro,
response = @gateway.purchase(@keep_card_amount, @uk_maestro,
:billing_address => @uk_maestro_address
)
assert_failure response
assert response.test?
end

def test_successful_authorization
response = @gateway.authorize(ACCEPT_AMOUNT, @uk_maestro,
response = @gateway.authorize(@accept_amount, @uk_maestro,
:billing_address => @uk_maestro_address
)
assert_success response
Expand All @@ -83,21 +84,21 @@ def test_no_login
@gateway = PslCardGateway.new(
:login => ''
)
response = @gateway.authorize(ACCEPT_AMOUNT, @uk_maestro,
response = @gateway.authorize(@accept_amount, @uk_maestro,
:billing_address => @uk_maestro_address
)
assert_failure response
assert response.test?
end

def test_successful_authorization_and_capture
authorization = @gateway.authorize(ACCEPT_AMOUNT, @uk_maestro,
authorization = @gateway.authorize(@accept_amount, @uk_maestro,
:billing_address => @uk_maestro_address
)
assert_success authorization
assert authorization.test?

capture = @gateway.capture(ACCEPT_AMOUNT, authorization.authorization)
capture = @gateway.capture(@accept_amount, authorization.authorization)

assert_success capture
assert capture.test?
Expand Down
56 changes: 37 additions & 19 deletions test/unit/gateways/psl_card_test.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
require File.dirname(__FILE__) + '/../../test_helper'

class PslCardTest < Test::Unit::TestCase
# 100 Cents
AMOUNT = 100

def setup
@gateway = PslCardGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
:login => 'LOGIN',
:password => 'PASSWORD'
)

@creditcard = credit_card('4242424242424242')
end

def test_successful_purchase
@creditcard.number = 1
assert response = @gateway.purchase(AMOUNT, @creditcard, {})
assert_success response
assert_equal '5555', response.authorization
assert response.test?
@credit_card = credit_card
@options = {
:billing_address => address,
:description => 'Store purchase'
}
@amount = 100
end

def test_successful_authorization
@creditcard.number = 1
assert response = @gateway.authorize(AMOUNT, @creditcard, {})
@gateway.expects(:ssl_post).returns(successful_purchase_response)
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert_equal '5555', response.authorization
assert_equal '08012522454901256086', response.authorization
assert response.test?
end

def test_unsuccessful_request
@creditcard.number = 2
assert response = @gateway.purchase(AMOUNT, @creditcard, {})
@gateway.expects(:ssl_post).returns(unsuccessful_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert response.test?
end
Expand All @@ -43,4 +38,27 @@ def test_supported_countries
def test_supported_card_types
assert_equal [ :visa, :master, :american_express, :diners_club, :jcb, :switch, :solo, :maestro ], PslCardGateway.supported_cardtypes
end

def test_avs_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)

response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'Y', response.avs_result['code']
end

def test_cvv_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)

response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'M', response.cvv_result['code']
end

private
def successful_purchase_response
"ResponseCode=00&Message=AUTHCODE:01256&CrossReference=08012522454901256086&First4=4543&Last4=9982&ExpMonth=12&ExpYear=2010&AVSCV2Check=ALL MATCH&Amount=1000&QAAddress=76 Roseby Avenue Manchester&QAPostcode=M63X 7TH&MerchantName=Merchant Name&QAName=John Smith"
end

def unsuccessful_purchase_response
"ResponseCode=05&Message=CARD DECLINED&QAAddress=The Parkway Larches Approach Hull North Humberside&QAPostcode=HU7 9OP&MerchantName=Merchant Name&QAName="
end
end

0 comments on commit 733102b

Please sign in to comment.