
Security News
Oxlint Introduces Type-Aware Linting Preview
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Super simple implementation of the Pin Payments API (pin.com.au) for Ruby and Rails projects.
PinPays is available as a gem:
$ gem install pin_pays
Configure your secret-key and whether to use the test or live modes:
# config/initializers/pin_pay.rb (for rails)
PinPays.configure do |config|
config.key = "your-secret-key" # NB: use the right one for the mode!
config.mode = :test # or :live
end
TIP: If you're using Rails 4+, I recommend using your secrets.yml file for the secret key.
PinPays replicates the PinPayments documented API closely. To understand the requirements for method inputs or return values refer to the PinPayments documentation, then refer to Responses section below to see how PinPays transforms the API json responses before giving them to you.
Examples:
# create a customer
customer = PinPays::Customers:create('moo@cow.com', 'card_token_xyz')
customer[:token] # => 'cust_token_xyz'
# issue a charge
charge = PinPays::Charges:create({ customer_token: customer[:token], email: 'moo@cow.com', description: 'Pants', amount: 4995, remote_ip: '127.0.0.1'})
charge[:token] # => 'charge_token_789'
# pay a refund
refund = PinPays::Refunds.create(charge[:token], 2500)
refund[:token] # => 'refund_token_123'
PinPays::Cards.create(card)
where card
is a hash of the card details
PinPays::Customers.create(email, card)
where card
is either a card_token (of a previously created card) or a hash of card details.
PinPays::Customers.list(page=nil)
where page
is the results page number to return (optional)
PinPays::Customers.show(customer_token)
PinPays::Customers.update(customer_token, options)
where options
is a hash of one or more of: email:
, card_token:
, or card:
(hash of card details).
PinPays::Customers.charges(customer_token, page=nil)
where page
is the results page number to return (optional)
PinPays::Charges.create(options)
where options
contains:
email:
, description:
, amount:
, and remote_ip:
customer_token:
, card_token:
, or card:
(hash of card details)currency:
, and capture:
PinPays::Charges.capture(charge_token)
PinPays::Charges.list(page=nil)
where page
is the results page number to return (optional)
PinPays::Charges.search(criteria)
where criteria
is a hash containing one or more criteria to search for.
PinPays::Charges.show(charge_token)
PinPays::Refunds.create(charge_token, amount=nil)
where amount
is the amount in cents of the original charge to refund (optional, otherwise the entire amount).
PinPays::Refunds.list(charge_token)
All successful calls return a hash. Fields of the hash are the same as those documented in PinPayments documentation (with some small convenience tweaks):
Non-paginated style responses have the parent "response" field omitted. For example, this:
{
"response": {
"token": "rf_ERCQy--Ay6o-NKGiUVcKKA",
"success": null,
"amount": 400,
"currency": "USD",
"charge": "ch_bZ3RhJnIUZ8HhfvH8CCvfA",
"created_at": "2012-10-27T13:00:00Z",
"error_message": null,
"status_message": "Pending"
}
}
becomes this:
{
token: "rf_ERCQy--Ay6o-NKGiUVcKKA",
success: null,
amount: 400,
currency: "USD",
charge: "ch_bZ3RhJnIUZ8HhfvH8CCvfA",
created_at: "2012-10-27T13:00:00Z",
error_message: null,
status_message: "Pending"
}
Note:
Additionally, paginated style responses like this:
{
"response": [
{
"token": "ch_lfUYEBK14zotCTykezJkfg",
"success": true,
"amount": 400,
"currency": "USD",
"description": "test charge",
"email": "roland@pin.net.au",
"ip_address": "203.192.1.172",
"created_at": "2012-06-20T03:10:49Z",
"status_message": "Success!",
"error_message": null,
"card": {
"token": "card_nytGw7koRg23EEp9NTmz9w",
"display_number": "XXXX-XXXX-XXXX-0000",
"expiry_month": 6,
"expiry_year": 2020,
"name": "Roland Robot",
"address_line1": "42 Sevenoaks St",
"address_line2": null,
"address_city": "Lathlain",
"address_postcode": "6454",
"address_state": "WA",
"address_country": "Australia",
"scheme": "master"
},
"captured": true,
"authorisation_expired": false,
"transfer": null,
"settlement_currency": "AUD"
}
],
"pagination": {
"current": 1,
"per_page": 25,
"count": 1
}
}
Become this:
{
items: [
{
token: "ch_lfUYEBK14zotCTykezJkfg",
success: true,
amount: 400,
currency: "USD",
description: "test charge",
email: "roland@pin.net.au",
ip_address: "203.192.1.172",
created_at: "2012-06-20T03:10:49Z",
status_message: "Success!",
error_message: null,
card: {
token: "card_nytGw7koRg23EEp9NTmz9w",
display_number: "XXXX-XXXX-XXXX-0000",
expiry_month: 6,
expiry_year: 2020,
name: "Roland Robot",
address_line1: "42 Sevenoaks St",
address_line2: null,
address_city: "Lathlain",
address_postcode: "6454",
address_state: "WA",
address_country: "Australia",
scheme: "master"
},
captured: true,
authorisation_expired: false,
transfer: null,
settlement_currency: "AUD"
}
],
pages: {
current: 1,
per_page: 25,
count: 1
}
}
Note that:
The only exception to the above is the PinPays::Refunds.list
call, which returns only an array of hashes.
All error responses result in an Exception of the type PinPays::ApiError
. The exception contains details about the specific error as properties on it:
...
rescue PinPays::ApiError => e
e.error # -> error code (ie: "insufficient_funds")
e.error_description # -> error description (ie: "There are not enough funds available to process the requested amount")
e.charge_token # -> of the failed charge (for charge-related api calls)
e.messages # -> an array of error messages (useful for displaying to the user on failed form submissions)
e.raw_response # -> the raw json api response as a ruby hash
end
...
For a list of possible error codes, and example responses see https://pin.net.au/docs/api/test-cards and the remainder of the PinPayments documentation pages.
Released under the MIT license.
FAQs
Unknown package
We found that pin_pays demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.