Giter Site home page Giter Site logo

paymill-ruby's Introduction

Paymill Build Status

This is a Ruby wrapper for Paymill's API.

Documentation

We use RubyDoc for documentation.

The documentation of the current release can be found here: http://rubydoc.info/gems/paymill/frames/index

Usage

First, you've to install the gem

gem install paymill

and require it

require "paymill"

Then you have to set your API key:

Paymill.api_key = "your-api-key"

Configuration

You can also set the API version, base endpoint and port:

Paymill.api_version = "v2"
Paymill.api_base    = "0.0.0.0"
Paymill.api_port    = 3000

Logging

Out of the box paymill-ruby will log all requests and responses to STDOUT, you can use any logger you want, though:

Paymill.logger = Logger.new(STDERR)

Clients

Paymill documentation on clients

Creating a new client:

Paymill::Client.create(email: "[email protected]", description: "He is a Ruby guy.")

Or find an existing client:

Paymill::Client.find("client_88a388d9dd48f86c3136")

Updating an existing client only works on an instance:

client = Paymill::Client.find("client_88a388d9dd48f86c3136")
client.update_attributes(email: "[email protected]")

Deleting a client:

Paymill::Client.delete("client_88a388d9dd48f86c3136")

For retrieving a collection of all clients you might use the all operation:

Paymill::Client.all

To sort and filter collection lists of objects, use the all method with an options hash. For example to find the most recent transactions belonging to a client you can use the following code:

Paymill::Transaction.all(client: "<client_id>", order: "created_at_desc")

Please note that Transactions and Payments cannot be updated.

Payments

Paymill documentation on payments

Creating a new credit card payment:

Paymill::Payment.create(token: "098f6bcd4621d373cade4e832627b4f6")

Creating a new debit card payment:

Paymill::Payment.create(type: "debit", code: "12345678", account: "1234512345", holder: "Max Mustermann")

Or finding an existing payment:

Paymill::Payment.find("pay_3af44644dd6d25c820a8")

Deleting a payment:

Paymill::Payment.delete("pay_3af44644dd6d25c820a8")

For retrieving a collection of all payments you might use the all operation:

Paymill::Payment.all

Transactions

Paymill documentation on transactions

A transaction can be executed as following

params = {
    :amount => 2000, # cents. Must be an integer
    :currency => 'USD', # iso
    :client => 'client_123', # client id. Use 'Paymill::Client'
    :payment => 'payment_123', # payment id. Use 'Paymill::Payment'
    :description => "some comment if needed"
}
Paymill::Transaction.create(params)

Offers

Paymill documentation on offers

Creating a new offer:

Paymill::Offer.create(name: "Monthly", interval: "1 month", amount: 1000, currency: "GBP", trial_period_days: 0)

Updating an offer (works on an Offer instance and only the name can be changed):

offer = Paymill::Offer.find("offer_08064e30032afa3aa046")
offer.update_attributes(name: "New name")

Deleting an offer:

Paymill::Offer.delete('offer_08064e30032afa3aa046')

Retrieving an offer:

Paymill::Offer.find("offer_753480df39aeb114f2f3")

Retrieving all offers:

Paymill::Offer.all

Webhooks

Paymill documentation on webhooks

Creating a new webhook:

Paymill::Webhook.create(email: "[email protected]", event_types: ["transaction.succeeded", "subscription.succeeded"])

Updating a webhook works on an instance (url/email and the event types can be changed):

hook = Paymill::Webhook.find("hook_940143bcdc0c40e7756f")
hook.update_attributes(email: "[email protected]")

Deleting a webhook:

Paymill::Webhook.delete("hook_940143bcdc0c40e7756f")

Retrieving a webhook:

hook = Paymill::Webhook.find("hook_940143bcdc0c40e7756f")

Retrieving all webhooks:

Paymill::Webhook.all

Refunds

Paymill documentation on refunds

Creating a new refund:

Paymill::Refund.create(id: "tran_023d3b5769321c649435", amount: 4200)

Retrieving a refund:

refund = Paymill::Refund.find("refund_87bc404a95d5ce616049")

Retrieving all refunds:

Paymill::Refund.all

Requirements

This gem requires Ruby 1.9 and faces version 2 of Paymill's API.

Bugs

Please report bugs at http://github.com/dkd/paymill-ruby/issues.

Note on Patches/Pull Requests

  • Fork the project from http://github.com/dkd/paymill-ruby.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2012-2014 dkd Internet Service GmbH, Stefan Sprenger. See LICENSE for details.

paymill-ruby's People

Contributors

abarre avatar acwebionate avatar andreaslyngstad avatar defsprite avatar dongennl avatar flippingbits avatar jacegu avatar lluis avatar molpe avatar nerian avatar nikoloff avatar ryanharkins avatar theodorton avatar thmsobrmlr avatar traxmaxx avatar zamith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paymill-ruby's Issues

Subscriptions trail_start & trail_end are not accessible

Hey,
is there any smart reason why attributes like "trail_start" or "trail_end" shouldn't be accessible for subscriptions?

in subscriptions.rb these attributes are not marked as accessible.
Since I always have to check with paymill if client is still entitled to use my product/service on login, would be nice if I could use these fields.

am I wrong?
thanks for your help

access Offer from Subscription

>> s = Paymill::Subscription.all.last
>> s.offer
NoMethodError: undefined method `offer' for #<Paymill::Subscription:0x00000006a20e30>
        from (irb):112
        from /usr/bin/irb:12:in `<main>'
>> s.plan
=> nil

on lib/paymill/subscription.rb attr_accessor should not contain offer instead plan?

attr_accessor :id, :offer, :livemode, :cancel_at_period_end, :canceled_at, :client, :trial_start, :trial_end

changing this works for me

Paymill::Payment doesn't respond to attributes

I've fetched a debit payment from my test env and saved it to the variable payment lets say.

payment outputs:

#<Paymill::Payment:0x007ffaab91abb0
@id="pay_69d459e8f85d10b6d4c01784",
@type="debit",
@client="client_f57da1337143c9383ffb",
@code="10010024",
@holder="gambo",
@account="*****6789",
@created_at=2013-08-27 05:39:02 +0200,
@updated_at=2013-08-27 05:39:03 +0200,
@app_id=nil>

When I try to access this data like payment.type it always claims that it is undefined.

Works

payment.id
=> "pay_69d459e8f85d10b6d4c01784"

payment.created_at
=> 2013-08-27 05:39:02 +0200

payment.updated_at
=> 2013-08-27 05:39:03 +0200

Doesn't work

payment.type
=> NoMethodError: undefined method `type' for Paymill::Payment

payment.client
=> NoMethodError: undefined method `client' for Paymill::Payment

payment.code
=> NoMethodError: undefined method `code' for Paymill::Payment

payment.holder
=> NoMethodError: undefined method `holder' for Paymill::Payment

payment.account
=> NoMethodError: undefined method `account' for Paymill::Payment

payment.app_id
=> NoMethodError: undefined method `app_id' for Paymill::Payment

I've already looked into the class https://github.com/dkd/paymill-ruby/blob/master/lib/paymill/payment.rb

it has an attr_accessor every attribute but app_id.

How can I fix this?

Best,
Gambo

Testing the API

Hi guys,

I've been looking at the tests and one thing strikes me as not being awesome, the tests are not validated against the real API.

By using WebMock, this wrapper may be completely outdated and the test will still be green, which I believe is a problem.

My proposal to solve this is twofold, and I would like to know your opinion before giving this any more thought.

First, I would build a fake server to mimic paymill's, this would allow us to get rid of webmock all together and just run the actual requests against this server. This is also nice for someone that wants to do integration testing on an app using this gem, so it's a win win situation.

This, however, does not solve the problem of green tests when in fact it's outdated. With a fake server set up, this problem could be solved by running the test locally against the fake server, so it is fast, but on the CI running it against a paymill's sandbox.

So, locally the tests would be fast, if the API changes in a way that is not supported by the gem, the tests on the CI fail and we can update the gem and the fake server (hopefully such drastic changes to the API won't happen often).

What do you think?

undefined method `update_attributes' for Paymill::Client

Hi everybody, I have a problem using the update operations on a Paymill Client. I use the same sample code given in the repo:

client = Paymill::Client.find(valid_client_id)
client.update_attributes(email: "Lets try it")

NoMethodError: undefined method `update_attributes' for #<Paymill::Client:0x007fb9dc75a8f8>

I investigate a little bit and it seems that the Paymill::Client class does not include the Paymill::Operation::Update module, or at least thats what the ruby console says.

Paymill::Client.included_modules
=> [Paymill::Operations::Find,
 Paymill::Operations::Delete,
 Paymill::Operations::Create,
 Paymill::Operations::All,
 Metaclass::ObjectMethods,
 Mocha::ObjectMethods,
 PP::ObjectMixin,
 FriendlyId::ObjectUtils,
 JSON::Ext::Generator::GeneratorMethods::Object,
 ActiveSupport::Dependencies::Loadable,
 Kernel]

Am I doing something wrong?

Add update support for Subscriptions.

v2 of the API allows for the updating of a subscription rather than deleting and creating a new one. Is this planned to be incorporated into the gem?

Are there plans to adapt to v2.1 of the API?

for example:

[main](0)--2014-09-12 13:39:04 +0200 >>Paymill::Subscription.update_attributes "sub_1cd06dcccbabb8272cc3", offer: "offer_0a5bd16a30f0db6fa567", offer_change_type: 0

Paymill::APIError: offer_change_type
from /Users/chusek/.rvm/gems/ruby-1.9.3-p392@droidmanager/gems/paymill-0.4.0/lib/paymill/request/validator.rb:27:in `validate_response_data'

undfined method next_capture_at

When I try to select the next_capture_at attribute I get an undefined method error. I thought there was a patch to make this accessible?

hostname was not match with the server certificate

Hi,

trying this out and thanks for creating this gem

I'm using the code from another question on here:

result = Paymill::Transaction.create(amount: 2000,
currency: "EUR",
description: "Milestone payment",
token: token)

but this gives me an error:
'hostname was not match with the server certificate'

seems to be some sort of SSL error. I'm totally stuck.
Many thanks for any help.

Hostname was not match with the server certificate

Hello,

I am trying to use you gem in my Ruby on Rails 3.2.9 application.
It works perfectly fine on my local Mac but on Heroku I get this error:

OpenSSL::SSL::SSLError (hostname was not match with the server certificate)

Is there something I need to do on Heroku or in code?

Thankful for all help!

create Token

I have no idea how to create the tokens for new payments. Would be great if there would be a function to create the tokens.

The development mode doesn't seem to work.

Hi guys,

If I try to turn Paymill.development to true, I get a first 400 error because the port is still set to 443. (request : http://api.paymill.com:443/v2/payments/)

So, I add Paymill.api_port = 80 to force the port but I get another error :

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

Any ideas ?

Missing functions update/delete

Hi guys,

I cannot update or delete subscriptions or payments? it says:

NoMethodError: undefined method `delete' for #Paymill::Payment:0x007f9471eab2c8

Any ideas?

INFO: gem 'paymill', '~> 0.4.0'

paymill gem 0.4.0 is dated September 2, 2013 (15.5 KB) on rubygems.org, while master branch is update recently:

latest commit ea32f1e4a8 Stefan Sprenger flippingbits authored on 29 Jul

is that correct or did you miss a gem bumping ?

Testing locally

Hi guys!
How do you test payments locally because of the ssl problem?

I tried tunnelss but I still get an error

Uncaught SecurityError: Blocked a frame with origin "https://ssl.kaptcha.com" from accessing a frame with origin "https://projectname.dev". Protocols, domains, and ports must match.

How do you test on your local machines? Thanks!!!

Dealing with multiple API keys

Currently the API key is set as a class level variable. I'm working on an application which has multiple paymill api keys. To handle this scenario, the public methods should optionally accept an api key as an argument.

Let me know if you have any ideas around this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.