-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flex Charge: Add support for TPV store #5120
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ class FlexChargeGateway < Gateway | |
authenticate: 'oauth2/token', | ||
purchase: 'evaluate', | ||
sync: 'outcome', | ||
refund: 'orders/%s/refund' | ||
refund: 'orders/%s/refund', | ||
store: 'tokenize' | ||
} | ||
|
||
SUCCESS_MESSAGES = %w(APPROVED CHALLENGE SUBMITTED SUCCESS).freeze | ||
|
@@ -43,6 +44,25 @@ def refund(money, authorization, options = {}) | |
commit(:refund, { amountToRefund: (money.to_f / 100).round(2) }, authorization) | ||
end | ||
|
||
def store(credit_card, options = {}) | ||
address = options[:billing_address] || options[:address] || {} | ||
first_name, last_name = address_names(address[:name], credit_card) | ||
|
||
post = { | ||
payment_method: { | ||
credit_card: { | ||
first_name: first_name, | ||
last_name: last_name, | ||
month: credit_card.month, | ||
year: credit_card.year, | ||
number: credit_card.number, | ||
verification_value: credit_card.verification_value | ||
}.compact | ||
} | ||
} | ||
commit(:store, post) | ||
end | ||
|
||
def supports_scrubbing? | ||
true | ||
end | ||
|
@@ -115,23 +135,29 @@ def add_invoice(post, money, credit_card, options) | |
avsResultCode: options[:avs_result_code], | ||
cvvResultCode: options[:cvv_result_code], | ||
cavvResultCode: options[:cavv_result_code], | ||
cardNotPresent: credit_card.verification_value.blank? | ||
cardNotPresent: credit_card.is_a?(String) ? false : credit_card.verification_value.blank? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just confirming: for TPV the cardNotPresent value will always be false. But for credit cards, will it be something true if no verification value is provided? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flex charge Documentation is not clear on this topic but the error messages during the testing led me to this conclusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable 👍 |
||
}.compact | ||
end | ||
|
||
def add_payment_method(post, credit_card, address, options) | ||
edgarv09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
post[:paymentMethod] = { | ||
holderName: credit_card.name, | ||
cardType: 'CREDIT', | ||
cardBrand: credit_card.brand&.upcase, | ||
cardCountry: address[:country], | ||
expirationMonth: credit_card.month, | ||
expirationYear: credit_card.year, | ||
cardBinNumber: credit_card.number[0..5], | ||
cardLast4Digits: credit_card.number[-4..-1], | ||
cardNumber: credit_card.number, | ||
Token: false | ||
}.compact | ||
payment_method = case credit_card | ||
when String | ||
{ Token: true, cardNumber: credit_card } | ||
else | ||
{ | ||
holderName: credit_card.name, | ||
cardType: 'CREDIT', | ||
cardBrand: credit_card.brand&.upcase, | ||
cardCountry: address[:country], | ||
expirationMonth: credit_card.month, | ||
expirationYear: credit_card.year, | ||
cardBinNumber: credit_card.number[0..5], | ||
cardLast4Digits: credit_card.number[-4..-1], | ||
cardNumber: credit_card.number, | ||
Token: false | ||
} | ||
end | ||
post[:paymentMethod] = payment_method.compact | ||
end | ||
|
||
def address_names(address_name, payment_method) | ||
|
@@ -205,7 +231,7 @@ def api_request(action, post, authorization = nil) | |
success_from(response), | ||
message_from(response), | ||
response, | ||
authorization: authorization_from(response), | ||
authorization: authorization_from(action, response), | ||
test: test?, | ||
error_code: error_code_from(response) | ||
) | ||
|
@@ -228,8 +254,8 @@ def message_from(response) | |
response[:title] || response[:responseMessage] || response[:status] | ||
end | ||
|
||
def authorization_from(response) | ||
response[:orderSessionKey] | ||
def authorization_from(action, response) | ||
action == :store ? response.dig(:transaction, :payment_method, :token) : response[:orderSessionKey] | ||
end | ||
|
||
def error_code_from(response) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Comment,
This should be a the bottom of the block