Skip to content

Commit

Permalink
Merge pull request #665 from stripe/remi-add-issuing-resources
Browse files Browse the repository at this point in the history
Add support for Issuing resources
  • Loading branch information
brandur-stripe authored Jul 26, 2018
2 parents 7c9492b + 04ae411 commit 69092da
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Metrics/LineLength:
# Offense count: 32
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 48
Max: 54

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 308
Max: 314

# Offense count: 6
# Configuration parameters: CountKeywordArgs.
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sudo: false
env:
global:
# If changing this number, please also change it in `test/test_helper.rb`.
- STRIPE_MOCK_VERSION=0.19.0
- STRIPE_MOCK_VERSION=0.23.0

cache:
directories:
Expand Down
6 changes: 6 additions & 0 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
require "stripe/invoice_item"
require "stripe/invoice_line_item"
require "stripe/issuer_fraud_record"
require "stripe/issuing/authorization"
require "stripe/issuing/card"
require "stripe/issuing/cardholder"
require "stripe/issuing/card_details"
require "stripe/issuing/dispute"
require "stripe/issuing/transaction"
require "stripe/login_link"
require "stripe/order"
require "stripe/order_return"
Expand Down
22 changes: 22 additions & 0 deletions lib/stripe/issuing/authorization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Stripe
module Issuing
class Authorization < Stripe::APIResource
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "issuing.authorization".freeze

def approve(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/approve", params, opts)
initialize_from(resp.data, opts)
end

def decline(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/decline", params, opts)
initialize_from(resp.data, opts)
end
end
end
end
18 changes: 18 additions & 0 deletions lib/stripe/issuing/card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Stripe
module Issuing
class Card < Stripe::APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "issuing.card".freeze

def details(params = {}, opts = {})
resp, opts = request(:get, resource_url + "/details", params, opts)
Util.convert_to_stripe_object(resp.data, opts)
end
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/issuing/card_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Stripe
module Issuing
class CardDetails < Stripe::StripeObject
OBJECT_NAME = "issuing.card_details".freeze
end
end
end
13 changes: 13 additions & 0 deletions lib/stripe/issuing/cardholder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Stripe
module Issuing
class Cardholder < Stripe::APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "issuing.cardholder".freeze
end
end
end
13 changes: 13 additions & 0 deletions lib/stripe/issuing/dispute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Stripe
module Issuing
class Dispute < Stripe::APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "issuing.dispute".freeze
end
end
end
12 changes: 12 additions & 0 deletions lib/stripe/issuing/transaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Stripe
module Issuing
class Transaction < Stripe::APIResource
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "issuing.transaction".freeze
end
end
end
96 changes: 51 additions & 45 deletions lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,51 +45,57 @@ def self.object_classes
ListObject::OBJECT_NAME => ListObject,

# business objects
Account::OBJECT_NAME => Account,
AlipayAccount::OBJECT_NAME => AlipayAccount,
ApplePayDomain::OBJECT_NAME => ApplePayDomain,
ApplicationFee::OBJECT_NAME => ApplicationFee,
ApplicationFeeRefund::OBJECT_NAME => ApplicationFeeRefund,
Balance::OBJECT_NAME => Balance,
BalanceTransaction::OBJECT_NAME => BalanceTransaction,
BankAccount::OBJECT_NAME => BankAccount,
BitcoinReceiver::OBJECT_NAME => BitcoinReceiver,
BitcoinTransaction::OBJECT_NAME => BitcoinTransaction,
Card::OBJECT_NAME => Card,
Charge::OBJECT_NAME => Charge,
CountrySpec::OBJECT_NAME => CountrySpec,
Coupon::OBJECT_NAME => Coupon,
Customer::OBJECT_NAME => Customer,
Dispute::OBJECT_NAME => Dispute,
EphemeralKey::OBJECT_NAME => EphemeralKey,
Event::OBJECT_NAME => Event,
ExchangeRate::OBJECT_NAME => ExchangeRate,
FileUpload::OBJECT_NAME => FileUpload,
Invoice::OBJECT_NAME => Invoice,
InvoiceItem::OBJECT_NAME => InvoiceItem,
InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
IssuerFraudRecord::OBJECT_NAME => IssuerFraudRecord,
LoginLink::OBJECT_NAME => LoginLink,
Order::OBJECT_NAME => Order,
OrderReturn::OBJECT_NAME => OrderReturn,
PaymentIntent::OBJECT_NAME => PaymentIntent,
Payout::OBJECT_NAME => Payout,
Plan::OBJECT_NAME => Plan,
Product::OBJECT_NAME => Product,
Recipient::OBJECT_NAME => Recipient,
RecipientTransfer::OBJECT_NAME => RecipientTransfer,
Refund::OBJECT_NAME => Refund,
Reversal::OBJECT_NAME => Reversal,
SKU::OBJECT_NAME => SKU,
Source::OBJECT_NAME => Source,
SourceTransaction::OBJECT_NAME => SourceTransaction,
Subscription::OBJECT_NAME => Subscription,
SubscriptionItem::OBJECT_NAME => SubscriptionItem,
ThreeDSecure::OBJECT_NAME => ThreeDSecure,
Token::OBJECT_NAME => Token,
Topup::OBJECT_NAME => Topup,
Transfer::OBJECT_NAME => Transfer,
UsageRecord::OBJECT_NAME => UsageRecord,
Account::OBJECT_NAME => Account,
AlipayAccount::OBJECT_NAME => AlipayAccount,
ApplePayDomain::OBJECT_NAME => ApplePayDomain,
ApplicationFee::OBJECT_NAME => ApplicationFee,
ApplicationFeeRefund::OBJECT_NAME => ApplicationFeeRefund,
Balance::OBJECT_NAME => Balance,
BalanceTransaction::OBJECT_NAME => BalanceTransaction,
BankAccount::OBJECT_NAME => BankAccount,
BitcoinReceiver::OBJECT_NAME => BitcoinReceiver,
BitcoinTransaction::OBJECT_NAME => BitcoinTransaction,
Card::OBJECT_NAME => Card,
Charge::OBJECT_NAME => Charge,
CountrySpec::OBJECT_NAME => CountrySpec,
Coupon::OBJECT_NAME => Coupon,
Customer::OBJECT_NAME => Customer,
Dispute::OBJECT_NAME => Dispute,
EphemeralKey::OBJECT_NAME => EphemeralKey,
Event::OBJECT_NAME => Event,
ExchangeRate::OBJECT_NAME => ExchangeRate,
FileUpload::OBJECT_NAME => FileUpload,
Invoice::OBJECT_NAME => Invoice,
InvoiceItem::OBJECT_NAME => InvoiceItem,
InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
IssuerFraudRecord::OBJECT_NAME => IssuerFraudRecord,
Issuing::Authorization::OBJECT_NAME => Issuing::Authorization,
Issuing::Card::OBJECT_NAME => Issuing::Card,
Issuing::CardDetails::OBJECT_NAME => Issuing::CardDetails,
Issuing::Cardholder::OBJECT_NAME => Issuing::Cardholder,
Issuing::Dispute::OBJECT_NAME => Issuing::Dispute,
Issuing::Transaction::OBJECT_NAME => Issuing::Transaction,
LoginLink::OBJECT_NAME => LoginLink,
Order::OBJECT_NAME => Order,
OrderReturn::OBJECT_NAME => OrderReturn,
PaymentIntent::OBJECT_NAME => PaymentIntent,
Payout::OBJECT_NAME => Payout,
Plan::OBJECT_NAME => Plan,
Product::OBJECT_NAME => Product,
Recipient::OBJECT_NAME => Recipient,
RecipientTransfer::OBJECT_NAME => RecipientTransfer,
Refund::OBJECT_NAME => Refund,
Reversal::OBJECT_NAME => Reversal,
SKU::OBJECT_NAME => SKU,
Source::OBJECT_NAME => Source,
SourceTransaction::OBJECT_NAME => SourceTransaction,
Subscription::OBJECT_NAME => Subscription,
SubscriptionItem::OBJECT_NAME => SubscriptionItem,
ThreeDSecure::OBJECT_NAME => ThreeDSecure,
Token::OBJECT_NAME => Token,
Topup::OBJECT_NAME => Topup,
Transfer::OBJECT_NAME => Transfer,
UsageRecord::OBJECT_NAME => UsageRecord,
}
end

Expand Down
2 changes: 2 additions & 0 deletions test/stripe/api_operations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MainResource < APIResource
OBJECT_NAME = "mainresource".freeze
nested_resource_class_methods :nested,
operations: %i[create retrieve update delete list]

OBJECT_NAME = "mainresource".freeze
end

should "define a create method" do
Expand Down
50 changes: 50 additions & 0 deletions test/stripe/issuing/authorization_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

require File.expand_path("../../../test_helper", __FILE__)

module Stripe
module Issuing
class AuthorizationTest < Test::Unit::TestCase
should "be listable" do
authorizations = Stripe::Issuing::Authorization.list
assert_requested :get, "#{Stripe.api_base}/v1/issuing/authorizations"
assert authorizations.data.is_a?(Array)
assert authorizations.data[0].is_a?(Stripe::Issuing::Authorization)
end

should "be retrievable" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
assert_requested :get, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end

should "be saveable" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.metadata["key"] = "value"
authorization.save
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/#{authorization.id}"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end

should "be updateable" do
authorization = Stripe::Issuing::Authorization.update("iauth_123", metadata: { foo: "bar" })
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end

should "be approveable" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.approve
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/approve"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end

should "be declineable" do
authorization = Stripe::Issuing::Authorization.retrieve("iauth_123")
authorization.decline
assert_requested :post, "#{Stripe.api_base}/v1/issuing/authorizations/iauth_123/decline"
assert authorization.is_a?(Stripe::Issuing::Authorization)
end
end
end
end
53 changes: 53 additions & 0 deletions test/stripe/issuing/card_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require File.expand_path("../../../test_helper", __FILE__)

module Stripe
module Issuing
class CardTest < Test::Unit::TestCase
should "be creatable" do
card = Stripe::Issuing::Card.create(
currency: "usd",
type: "physical"
)
assert_requested :post, "#{Stripe.api_base}/v1/issuing/cards"
assert card.is_a?(Stripe::Issuing::Card)
end

should "be listable" do
cards = Stripe::Issuing::Card.list
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards"
assert cards.data.is_a?(Array)
assert cards.data[0].is_a?(Stripe::Issuing::Card)
end

should "be retrievable" do
card = Stripe::Issuing::Card.retrieve("ic_123")
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123"
assert card.is_a?(Stripe::Issuing::Card)
end

should "be saveable" do
card = Stripe::Issuing::Card.retrieve("ic_123")
card.metadata["key"] = "value"
card.save
assert_requested :post, "#{Stripe.api_base}/v1/issuing/cards/ic_123"
assert card.is_a?(Stripe::Issuing::Card)
end

should "be updateable" do
card = Stripe::Issuing::Card.update("ic_123", metadata: { foo: "bar" })
assert_requested :post, "#{Stripe.api_base}/v1/issuing/cards/ic_123"
assert card.is_a?(Stripe::Issuing::Card)
end

should "be able to retrieve card details" do
card = Stripe::Issuing::Card.retrieve("ic_123")

card_details = card.details
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details"
assert card_details.is_a?(Stripe::Issuing::CardDetails)
end
end
end
end
Loading

0 comments on commit 69092da

Please sign in to comment.