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

API changes #3

Open
florish opened this issue Jul 9, 2015 · 0 comments
Open

API changes #3

florish opened this issue Jul 9, 2015 · 0 comments

Comments

@florish
Copy link
Contributor

florish commented Jul 9, 2015

A while ago, I wrote out some pseudo code while thinking about how we could improve the API for developers using it. Idea is to support all of Buckaroo's NVP actions, while keeping the code as Ruby-ish as possible.

This is a work in progress and I'm very much open to suggestions.

# Create a Transaction object, specify the gateway action later
t = BuckarooClient.transaction(invoicenumber: 'F2014.0001')
t.select_service(:pay_per_email) do |s|
  # Add main transaction variables here...
end

# Support for custom and additional variables (see Buckaroo docs for explanation)
t.custom_variables = {
  key: 'value'
}
t.additional_variables = {
  key: 'value'
}
t.additional_variables << key: 'value', another_key: 'another_value'

# Create an NVP transaction request afterwards and send it out
req = t.transaction_request
req.send!

# ... or, use one of the other available requests
# Drawback: this doesn't really fit for all request types.
# E.g. `invoice_info` does not need to know what kind of payment service is used.
t.invoice_info
t.transaction_status
t.refund_info
t.transaction_request_specification
t.cancel_transaction

# Optional batch support...
# ...but I think we shouldn't support this.
# Sending transactions one by one gives one-on-one success and error messages.
batch = BuckarooClient.batch
batch << transaction
batch.to_csv

# Another possible approach: expose a `gateway` object with all of the 
# available request types as public methods
gateway = BuckarooClient.gateway
gateway.invoice_info(invoicenumber: 'F00001')
gateway.invoice_info(customercode: 'ABC123')

# ...or, skip the `gateway` object altogether.
# Simply expose all NVP gateway request types as class-level methods
t = BuckarooClient.transaction_request
t.invoicenumber = 'F0001'
t.amount = '2.34'
t.culture = 'nl-BE'
t.select_service(:pay_per_email) do |s|
  # ... set necessary variables for this service
end

# Another approach: simply set all transaction variables in the initializer
# and fire the request right way.
response = BuckarooClient.transaction_request(
  invoicenumber: 'F0001',
  amount: '2.34',
  services: [
    {
      type: :pay_per_email,
      foo: 'bar',
      x: 'y'
    },
    {
      type: :credit_management,
      a: 'b'
    }
  ]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant