Added support for the new Payout and RecipientTransfer objects

The Transfer object used to represent all movements of funds in Stripe. It
split in three resources:
- Transfer: this describes the movement of funds between Stripe accounts
and is specific to Stripe Connect.
- Payout: this describes the movement of funds from a Stripe account to a
bank account, debit card or any future payout method.
- RecipientTransfer: this describes the movement of funds from a Stripe
account to a Recipient's card or Bank Account. This is here for legacy
reasons and can only be accessed from an expanded BalanceTransaction.

This change is behind an API version so old API versions would still use
the Transfer object for everything while new API version would see the
split.

This applies beyond the new object as some properties/methods are removed
from Transfer and other properties are renamed on other objects.
This commit is contained in:
Remi Jannel 2017-03-26 09:23:34 -04:00
parent f9fda0ed4c
commit 65e8f505d5
5 changed files with 74 additions and 0 deletions

View File

@ -52,9 +52,11 @@ require 'stripe/invoice'
require 'stripe/invoice_item'
require 'stripe/order'
require 'stripe/order_return'
require 'stripe/payout'
require 'stripe/plan'
require 'stripe/product'
require 'stripe/recipient'
require 'stripe/recipient_transfer'
require 'stripe/refund'
require 'stripe/reversal'
require 'stripe/sku'

16
lib/stripe/payout.rb Normal file
View File

@ -0,0 +1,16 @@
module Stripe
class Payout < APIResource
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Save
def cancel
resp, api_key = self.request(:post, cancel_url)
initialize_from(resp.data, api_key)
end
def cancel_url
resource_url + '/cancel'
end
end
end

View File

@ -0,0 +1,4 @@
module Stripe
class RecipientTransfer < StripeObject
end
end

View File

@ -45,9 +45,11 @@ module Stripe
'invoiceitem' => InvoiceItem,
'order' => Order,
'order_return' => OrderReturn,
'payout' => Payout,
'plan' => Plan,
'product' => Product,
'recipient' => Recipient,
'recipient_transfer' => RecipientTransfer,
'refund' => Refund,
'sku' => SKU,
'source' => Source,

View File

@ -0,0 +1,50 @@
require File.expand_path('../../test_helper', __FILE__)
module Stripe
class PayoutTest < Test::Unit::TestCase
FIXTURE = API_FIXTURES.fetch(:payout)
should "be listable" do
payouts = Stripe::Payout.list
assert_requested :get, "#{Stripe.api_base}/v1/payouts"
assert payouts.data.kind_of?(Array)
assert payouts.data[0].kind_of?(Stripe::Payout)
end
should "be retrievable" do
payout = Stripe::Payout.retrieve(FIXTURE[:id])
assert_requested :get, "#{Stripe.api_base}/v1/payouts/#{FIXTURE[:id]}"
assert payout.kind_of?(Stripe::Payout)
end
should "be creatable" do
payout = Stripe::Payout.create(
amount: 100,
currency: "USD"
)
assert_requested :post, "#{Stripe.api_base}/v1/payouts"
assert payout.kind_of?(Stripe::Payout)
end
should "be saveable" do
payout = Stripe::Payout.retrieve(FIXTURE[:id])
payout.metadata['key'] = 'value'
payout.save
assert_requested :post, "#{Stripe.api_base}/v1/payouts/#{FIXTURE[:id]}"
end
should "be updateable" do
payout = Stripe::Payout.update(FIXTURE[:id], metadata: {foo: 'bar'})
assert_requested :post, "#{Stripe.api_base}/v1/payouts/#{FIXTURE[:id]}"
assert payout.kind_of?(Stripe::Payout)
end
context "#cancel" do
should "cancel a payout" do
payout = Stripe::Payout.retrieve(FIXTURE[:id])
payout = payout.cancel
assert payout.kind_of?(Stripe::Payout)
end
end
end
end