Skip to content
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

Support extra data for Barclay Smartcard credits #2631

Merged
merged 1 commit into from Oct 26, 2017

Conversation

bpollack
Copy link
Contributor

Barclays Smartcard will be requiring credits that lack a PSP to include four additional pieces of information: the date-of-birth, entity type, nationality, and full name of the person requesting the credit. This change enables including them.

@@ -60,7 +60,13 @@ def credit(money, creditcard, options = {})
post = payment_request(money, options)
post[:amount] = amount_hash(money, options[:currency])
post[:card] = credit_card_hash(creditcard)

if !options.has_key?(:order_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find this pattern elsewhere, but it seemed like a really clean way of handling this client-side. Other reasonable options would be to do this, but without the requires! line; or just to unconditionally pass through these attributes, if they exist.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've typically seen the pattern of conditionally adding each option individually vs the use of requires!. Example:

post[:dateOfBirth] = if options[:date_of_birth]
post[:entityType] = if options[:entity_type]
post[:nationality] =  if options[:nationality]

I don't have the full scope of changes in my head so I'm assuming that each item can be sent to the gateway individually instead of requiring the entire group of options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the full scope of changes in my head so I'm assuming that each item can be sent to the gateway individually instead of requiring the entire group of options.

In this particular case, the absence of an order ID requires all four options at once; none are optional, and none are required for other transaction types—hence this style of requires!. (More details in the JIRA ticket this branch is named after, if you're bored.) Whether it should be ActiveMerchant's job to do this, and whether shoving a requires! halfway through the method, are still points I'm not clear on. It definitely works, but it's a pattern I didn't see in other adapters I glanced at.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of the order_id check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yeah it's more common to check the fields individually than with a requires! block. We usually let users send whatever they have and leave out what they don't, and get a error message from the gateway. Depends on how the gateway responds to missing or blank fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order_id check is because those fields aren't required if it's present. The alternative to doing it this way would be to say that it's not ActiveMerchant's problem to tell you you're missing fields, at which point this method would instead become:

def credit(money, creditcard, options = {})
  post = payment_request(money, options)
  post[:amount] = amount_hash(money, options[:cgurrency])
  post[:card] = credit_card_hash(creditcard)
  post[:dateOfBirth] = options[:date_of_birth] if options[:date_of_birth]
  post[:entityType]  = options[:entity_type] if options[:entity_type]
  post[:nationality] = options[:nationality] if options[:nationality]
  post[:shopperName] = options[:shopper_name] if options[:shopper_name]
  commit('refundWithData', post)
end

This seemed harsher to the user and doesn't save us much work, but it permits greater flexibility on the part of the gateway.

post[:dateOfBirth] = options[:date_of_birth]
post[:entityType] = options[:entity_type]
post[:nationality] = options[:nationality]
post[:shopperName] = options[:shopper_name]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be pulled out of the credit card, but I was a bit ambivalent on whether that actually made sense. Nationality, entity type, and date of birth obviously cannot be pulled out of that field, so having this consistently be its own set of data seemed saner to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does as well. Typically I add a || creditcard.name as a fallback in these situations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I see with the requires! it would never trigger...

@@ -60,7 +60,13 @@ def credit(money, creditcard, options = {})
post = payment_request(money, options)
post[:amount] = amount_hash(money, options[:currency])
post[:card] = credit_card_hash(creditcard)

if !options.has_key?(:order_id)
requires!(options, [:date_of_birth, :entity_type, :nationality, :shoper_name])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in shopper_name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangit. Fixing.

@bpollack bpollack force-pushed the enrg-7107-barclays-payouts branch 3 times, most recently from 6edcec2 to 89485fe Compare October 26, 2017 14:23
@bpollack
Copy link
Contributor Author

Okay, all changes we talked about @curiousepic are in here. Code does much less and doesn't confuse :order_id for a pspReference anymore.

post[:dateOfBirth] = options[:date_of_birth] if options[:date_of_birth]
post[:entityType] = options[:entity_type] if options[:entity_type]
post[:nationality] = options[:nationality] if options[:nationality]
post[:shopperName] = options[:shopper_name] if options[:shopper_name]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now without the requires! we can at least be helpful with a fallback like || creditcard.name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this, but as I started updating the tests to handle it, I realized I disagree with the feature: for us to do this, you'd have to 1) issue a credit, 2) successfully supply the date of birth, entity type, and nationality, but 3) forget shopper name. That's already an edge case of an edge case, but yoinking data from the credit card fields has a fun side-effect that the user may get the credit rejected for having the wrong shopper name, and then will be trying to figure out how that's even possible/what the shopper name was in the first place.

I thus think this is probably the best path forward as-is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fair 👍

@curiousepic
Copy link
Contributor

Otherwise looks good, this is probably the best we can do for now.

Barclays Smartcard will be requiring credits that lack a PSP to include four additional pieces of information: the date-of-birth, entity type, nationality, and full name of the person requesting the credit. This change enables including them for credit requests.
@bpollack bpollack merged commit dcbde8c into master Oct 26, 2017
@bpollack bpollack deleted the enrg-7107-barclays-payouts branch October 26, 2017 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants