Skip to content

API changes #3

@florish

Description

@florish

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'
    }
  ]
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions