Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pr-pin

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pr-pin

  • 0.7.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

PR::Pin

Installation

Add this line to your application's Gemfile:

gem 'pr-pin'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pr-pin

Usage

Registering Connections

# Require the gem
require 'pr-pin'

# Register a connection using your Pin Payments secret key
PR::Pin.register_connection(
  secret_key: 'your_secret_key',
  # raise on error, defaults to returning PR::Pin::API::Error instance
  error_handler: ->(exception) { raise(exception) },
  sandbox: true # Defaults to true, false for production
)

# You can register another connection by passsing an identifier to
# PR::Pin.register_connection, i.e.
PR::Pin.register_connection(
  :admin, # defaults to :default
  secret_key: 'your_secret_key',
  sandbox: true
)

# Then, you can specify the connection to use when resolving the
# endpoint repository from the PR::Pin container
customers = PR::Pin.customers(:admin).list(page: 1)
# => [#<PR::Pin::Struct::Customer>, ...]
customers.current_page # => 1
customers.per_page # => 25
customers.prev_page # => nil
customers.next_page # => 2
customers.total_count # => 53
customers.total_pages # => 3

One-off charge

# Create a charge using a token, you can get a card token
# using Pin Payments hosted fields, or by creating a card
# via the API, this can be used to take a one-off payment
charge = PR::Pin.charges.create(
  email: 'a.user@petrescue.com.au',
  description: 'A $10 donation',
  amount: 1000,
  ip_address: '127.0.0.1',
  card_token: 'card_58b6c52f131956c4394ba7'
)
charge.success? # => true
charge.error? # => false
charge # => #<PR::Pin::Struct::Charge>

# Find a charge by token
PR::Pin.charges.find('ch_1ee2d1')
# => #<PR::Pin::Struct::Charge>

Recurring payments

# For a subscription, create a customer using a card token
customer = PR::Pin.customers.create(
  email: 'a.user@petrescue.com.au',
  card_token: 'card_58b6c52f131956c4394ba7'
)
customer.success? # => true
customer.error? # => false
customer # => #<PR::Pin::Struct::Customer>

# And then attach a subscription using the plan token from
# the plans endpoint (you will need to create the plan first)
subscription = PR::Pin.subscriptions.create(
  plan_token: 'plan_2d16b31863015a57820b70',
  customer_token: 'cus_9d18a4516a6ae777-NDecB'
)
subscription.success? # => true
subscription.error? # => false
subscription # => #<PR::Pin::Struct::Subscription>

ledger = PR::Pin.ledger.for_subscription('sub_293857')
subscription.success? # => true
subscription.error? # => false
ledger
# => [
#   #<PR::Pin::Struct::Ledger type="credit" annotation="charge_credit" amount=1026 currency="AUD" created_at=#<DateTime: 2020-07-02T02:19:50+00:00 ((2459033j,8390s,0n),+0s,2299161j)>>,
#   #<PR::Pin::Struct::Ledger type="debit" annotation="interval_fee" amount=1026 currency="AUD" created_at=#<DateTime: 2020-07-02T02:19:47+00:00 ((2459033j,8387s,0n),+0s,2299161j)>>,
#   #<PR::Pin::Struct::Ledger type="debit" annotation="setup_fee" amount=0 currency="AUD" created_at=#<DateTime: 2020-07-02T02:19:47+00:00 ((2459033j,8387s,0n),+0s,2299161j)>>
# ]

Refunds

# List refunds (paginated)
refunds = PR::Pin.refunds.list
# => [#<PR::Pin::Struct::Refund>, ...]

# Find a specific refund
refund = PR::Pin.refunds.find('rf_1e5429')
# => #<PR::Pin::Struct::Refund>

# Create a refund for a charge
PR::Pin.refunds.create_for_charge('ch_1ee2d1')
# => #<PR::Pin::Struct::Refund>

# List all refunds by charge
PR::Pin.refunds.for_charge('ch_1ee2d1')
# => [#<PR::Pin::Struct::Refund>, ...]

Errors - See PR::Pin::API::Error

charge = PR::Pin.charges.create(
  email: 'a.user@petrescue.com.au'
)
charge.success? # => false
charge.error? # => true
charge.code # => "invalid_resource"
charge.description # => "One or more parameters were missing or invalid"
charge # => => #<PR::Pin::API::Error>

API Coverage

Coverage of https://pinpayments.com/developers/api-reference

RelationEndpointDescriptionDocsImplemented
BalanceGET /balanceReturns the current balance of your Pin Payments account:link::x:
Bank AccountsPOST /bank_accountsCreates a bank account token:link::x:
CardsPOST /cardsSecurely stores a card's details:link::x:
ChargesPOST /chargesCreates a new charge:link::heavy_check_mark:
ChargesPUT /charges/#{charge-token}/captureCaptures a previously authorised charge:link::x:
ChargesGET /chargesReturns a paginated list of all charges:link::heavy_check_mark:
ChargesGET /charges/searchReturns a paginated list of charges matching the search criteria:link::heavy_check_mark:
ChargesGET /charges/#{charge-token}Returns the details of a charge:link::heavy_check_mark:
CustomersPOST /customersCreates a new customer:link::heavy_check_mark:
CustomersGET /customersReturns a paginated list of all customers:link::heavy_check_mark:
CustomersGET /customers/#{customer-token}Returns the details of a customer:link::heavy_check_mark:
CustomersPUT /customers/#{customer-token}Updates the details of a customer:link::heavy_check_mark:
CustomersDELETE /customers/#{customer-token}Deletes a customer and all of its cards:link::x:
CustomersGET /customers/#{customer-token}/chargesReturns a paginated list of a customer's charges:link::heavy_check_mark:
CustomersGET /customers/#{customer-token}/cardsReturns a paginated list of a customer's cards:link::x:
CustomersPOST /customers/#{customer-token}/cardsCreates an additional card for the specified customer:link::x:
CustomersDELETE /customers/#{customer-token}/cards/#{card-token}Deletes a customer's non-primary card:link::x:
CustomersGET /customers/#{customer-token}/subscriptionsRetrieves the specified customer's subscriptions:link::x:
EventsGET /eventsReturns a paginated list of all events:link::x:
EventsGET /events/#{event-token}Returns the details of the specified event:link::x:
PlansPOST /plansCreates a new plan:link::heavy_check_mark:
PlansGET /plansReturns a paginated list of all plans:link::heavy_check_mark:
PlansGET /plans/#{plan-token}Returns the details of a specified plan:link::heavy_check_mark:
PlansPUT /plans/#{plan-token}Update the specified plan:link::heavy_check_mark:
PlansDELETE /plans/#{plan-token}Deletes a plan and all of its subscriptions:link::x:
PlansPOST /plans/#{plan-token}/subscriptionsCreates a new subscription to the specified plan:link::x:
PlansGET /plans/#{plan-token}/subscriptionsReturns a paginated list of subscriptions for a plan:link::x:
SubscriptionsPOST /subscriptionsActivate a new subscription and returns its details:link::heavy_check_mark:
SubscriptionsGET /subscriptionsReturns a paginated list of all subscriptions:link::heavy_check_mark:
SubscriptionsGET /subscriptions/#{sub-token}Returns the details of the subscription identified by subscription token:link::heavy_check_mark:
SubscriptionsPUT /subscriptions/#{sub-token}Updates the card associated with a subscription identified by subscription token:link::heavy_check_mark:
SubscriptionsDELETE /subscriptions/#{sub-token}Cancels the subscription identified by subscription token:link::x:
SubscriptionsPUT /subscriptions/#{sub-token}/reactivateReactivates the subscription identified by subscription token:link::x:
SubscriptionsGET /subscriptions/#{sub-token}/ledgerFetch the ledger entries relating to a subscription identified by subscription token:link::heavy_check_mark:
RecipientsPOST /recipientsCreates a new recipient:link::x:
RecipientsGET /recipientsReturns a paginated list of all recipients:link::x:
RecipientsGET /recipients/#{recipient-token}Returns the details of a recipient:link::x:
RecipientsPUT /recipients/#{recipient-token}Updates the details of a recipient:link::x:
RecipientsGET /recipients/#{recipient-token}/transfersReturns a paginated list of a recipient's transfers:link::x:
RefundsGET /refundsReturns a paginated list of all refunds:link::heavy_check_mark:
RefundsGET /refunds/#{refund-token}Returns the details of the specified refund:link::heavy_check_mark:
RefundsPOST /charges/#{charge-token}/refundsCreates a new refund and returns its details:link::heavy_check_mark:
RefundsGET /charges/#{charge-token}/refundsReturns a list of all refunds for the specified charge:link::heavy_check_mark:
TransfersPOST /transfersCreates a new transfer:link::x:
TransfersGET /transfersReturns a paginated list of all transfers:link::x:
TransfersGET /transfers/searchReturns a paginated list of transfers matching the search criteria:link::x:
TransfersGET /transfers/#{transfer-token}Returns the details of the specified transfer:link::x:
TransfersGET /transfers/#{transfer-token}/line_itemsReturns a paginated list of line items associated with the specified transfer:link::x:
Webhook EndpointsPOST /webhook_endpointsCreates a new webhook endpoint:link::x:
Webhook EndpointsGET /webhook_endpointsReturns a paginated list of all webhook endpoints:link::x:
Webhook EndpointsGET /webhook_endpoints/#{webhook-endpoint-token}Returns the details of the specified webhook endpoint:link::x:
Webhook EndpointsDELETE /webhook_endpoints/#{webhook-endpoint-token}Deletes a webhook endpoint and all of its webhook requests:link::x:
WebhooksGET /webhooksReturns a paginated list of all webhooks:link::x:
WebhooksGET /webhooks/#{webhook-token}Returns the details of a webhook:link::x:
WebhooksPUT /webhooks/#{webhook-token}/replayReplays a webhook:link::x:

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/PetRescue/pr-pin.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 04 Nov 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc