Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion lib/Net/Stripe.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Net::Stripe::Token;
use Net::Stripe::Invoiceitem;
use Net::Stripe::Invoice;
use Net::Stripe::Card;
use Net::Stripe::BitcoinReceiver;
use Net::Stripe::Plan;
use Net::Stripe::Coupon;
use Net::Stripe::Charge;
Expand All @@ -22,6 +23,7 @@ use Net::Stripe::BalanceTransaction;
use Net::Stripe::List;
use Net::Stripe::LineItem;
use Net::Stripe::Refund;
use Net::Stripe::BitcoinTransaction;

# ABSTRACT: API client for Stripe.com

Expand Down Expand Up @@ -94,7 +96,7 @@ L<https://stripe.com/docs/api#create_charge>

=item * customer - L<Net::Stripe::Customer>, HashRef or Str - customer to charge - optional

=item * card - L<Net::Stripe::Card>, L<Net::Stripe::Token>, Str or HashRef - card to use - optional
=item * card - L<Net::Stripe::Card>, L<Net::Stripe::Token>, Str or HashRef - card to use; also accepts bitcoin receiver id - optional

=item * description - Str - description for the charge - optional

Expand Down Expand Up @@ -1428,6 +1430,118 @@ InvoiceItems: {
}
}

=bitcoinreceiver_method create_bitcoin_receiver

Create a new bitcoin receiver

L<https://stripe.com/docs/api#create_bitcoin_receiver>

=over

=item * amount - Int, required

=item * currency - Str, required (as of Stripe API v2015-09-08, usd only)

=item * email - Str, required

=item * description - Str, optional

=item * metadata - HashRef, optional

=item * refund_mispayments - Bool, optional

=back

Returns a L<Net::Stripe::BitcoinReceiver>

$stripe->create_bitcoin_receiver(amount => 1000, currency => 'usd', email => '[email protected]');

=bitcoinreceiver_method get_bitcoin_receiver

Retreives an existing Bitcoin receiver.

L<https://stripe.com/docs/api#retrieve_bitcoin_receiver>

=over

=item * receiver_id - Str, required

=back

Returns a L<Net::Stripe::BitcoinReceiver>

$stripe->get_bitcoin_receiver(receiver_id => 'btcreceiverid');

=bitcoinreceiver_method list_bitcoin_receivers

Return a list of Bitcoin receivers

L<https://stripe.com/docs/api#list_bitcoin_receivers>

=over

=item * ending_before - Str, optional

=item * limit - Int, optional

=item * starting_after - Str, optional

=item * filled - Bool, optional

=item * active - Bool, optional

=item * uncaptured_funds - Bool, optional

=back

Returns a L<Net::Stripe::List> object containing L<Net::Stripe::BitcoinReceiver> objects.

$stripe->list_bitcoin_receivers();

=cut

BitcoinReceivers: {
method create_bitcoin_receiver(Int :$amount,
Str :$currency,
Str :$email,
Str :$description?,
HashRef :$metadata?,
Bool :$refund_mispayments?) {

my $receiver = Net::Stripe::BitcoinReceiver->new(
amount => $amount,
currency => $currency,
email => $email,
description => $description,
metadata => $metadata,
refund_mispayments => $refund_mispayments
);
return $self->_post( 'bitcoin/receivers', $receiver );
}

method get_bitcoin_receiver(Str :$receiver_id) {
return $self->_get("bitcoin/receivers/$receiver_id");
}

method list_bitcoin_receivers(Bool :$active?,
Bool :$filled?,
Str :$ending_before?,
Int :$limit?,
Str :$starting_after?,
Bool :$uncaptured_funds?) {

return $self->_get_collections(
"bitcoin/receivers",
ending_before => $ending_before,
limit => $limit,
starting_after => $starting_after,
active => $active,
filled => $filled,
uncaptured_funds => $uncaptured_funds
);
}
}

# Helper methods

method _get(Str $path) {
Expand Down
42 changes: 42 additions & 0 deletions lib/Net/Stripe/BitcoinReceiver.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Net::Stripe::BitcoinReceiver;

use Moose;
use Kavorka;
extends 'Net::Stripe::Resource';

# ABSTRACT: represent a Bitcoin Receiver object from Stripe

# Args for creating a Receiver
has 'amount' => ( is => 'ro', isa => 'Int', required => 1 );
has 'currency' => ( is => 'ro', isa => 'Str', required => 1 );
has 'email' => ( is => 'ro', isa => 'Str', required => 1 );
has 'description' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'metadata' => ( is => 'rw', isa => 'Maybe[HashRef]' );
has 'refund_mispayments' => ( is => 'ro', isa => 'Maybe[Bool]' );

# Args returned by the API
has 'id' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'created' => ( is => 'ro', isa => 'Maybe[Int]' );
has 'livemode' => ( is => 'ro', isa => 'Maybe[Bool|Object]' );
has 'active' => ( is => 'ro', isa => 'Maybe[Bool|Object]' );
has 'amount_received' => ( is => 'ro', isa => 'Maybe[Int]' );
has 'bitcoin_amount' => ( is => 'ro', isa => 'Maybe[Int]' );
has 'bitcoin_amount_received' => ( is => 'ro', isa => 'Maybe[Int]' );
has 'bitcoin_uri' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'filled' => ( is => 'ro', isa => 'Maybe[Bool|Object]' );
has 'inbound_address' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'uncaptured_funds' => ( is => 'ro', isa => 'Maybe[Bool|Object]' );
has 'refund_address' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'used_for_payment' => ( is => 'ro', isa => 'Maybe[Bool|Object]' );
has 'customer' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'payment' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'transactions' => ( is => 'ro', isa => 'Maybe[Net::Stripe::List]' );

method form_fields () {
return ( $self->form_fields_for_metadata(),
map { $_ => $self->$_ }
grep { defined $self->$_ } qw/amount currency email description refund_mispayments/ );
}

__PACKAGE__->meta->make_immutable;
1;
17 changes: 17 additions & 0 deletions lib/Net/Stripe/BitcoinTransaction.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Net::Stripe::BitcoinTransaction;

use Moose;
use Kavorka;
extends 'Net::Stripe::Resource';

# ABSTRACT: represent a Bitcoin Transaction object from Stripe

# Args for creating a Receiver
has 'id' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'amount' => ( is => 'ro', isa => 'Maybe[Int]' );
has 'bitcoin_amount' => ( is => 'ro', isa => 'Maybe[Int]' );
has 'currency' => ( is => 'ro', isa => 'Maybe[Str]' );
has 'receiver' => ( is => 'ro', isa => 'Maybe[Str]' );

__PACKAGE__->meta->make_immutable;
1;
2 changes: 1 addition & 1 deletion lib/Net/Stripe/Charge.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ has 'created' => (is => 'ro', isa => 'Maybe[Int]');
has 'amount' => (is => 'ro', isa => 'Maybe[Int]', required => 1);
has 'currency' => (is => 'ro', isa => 'Maybe[Str]', required => 1);
has 'customer' => (is => 'ro', isa => 'Maybe[Str]');
has 'card' => (is => 'ro', isa => 'Maybe[Net::Stripe::Token|Net::Stripe::Card|Str]');
has 'card' => (is => 'ro', isa => 'Maybe[Net::Stripe::Token|Net::Stripe::Card|Net::Stripe::BitcoinReceiver|Str]');
has 'description' => (is => 'ro', isa => 'Maybe[Str]');
has 'livemode' => (is => 'ro', isa => 'Maybe[Bool|Object]');
has 'paid' => (is => 'ro', isa => 'Maybe[Bool|Object]');
Expand Down
46 changes: 46 additions & 0 deletions t/live.t
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ Charges: {
ok $charge->paid, 'charge was paid';
}

Post_charge_using_bitcoin_receiver: {
my $receiver = $stripe->create_bitcoin_receiver(
amount => 1000,
currency => 'usd',
email => '[email protected]'
);
my $charge = $stripe->post_charge(
amount => $receiver->amount,
currency => $receiver->currency,
card => $receiver->id,
);
isa_ok $charge, 'Net::Stripe::Charge';
ok $charge->paid, 'charge was paid';
}

Rainy_day: {
# swallow the expected warning rather than have it print out durring tests.
close STDERR;
Expand Down Expand Up @@ -547,4 +562,35 @@ Invoices_and_items: {
}
}

Bitcoin_Receivers: {
Basic_successful_use: {
{
my $receiver = Net::Stripe::BitcoinReceiver->new(
amount => 1000,
currency => 'usd',
email => '[email protected]'
);
isa_ok $receiver, 'Net::Stripe::BitcoinReceiver',
'got a receiver back';
}

my $receiver = $stripe->create_bitcoin_receiver(
amount => 1000,
currency => 'usd',
email => '[email protected]'
);
isa_ok $receiver, 'Net::Stripe::BitcoinReceiver',
'got a receiver back from create';

my $same = $stripe->get_bitcoin_receiver(
receiver_id => $receiver->id );
is $same->id, $receiver->id, 'receiver id matches';

# Test ability to add, retrieve lists of receivers
my $btc_list = $stripe->list_bitcoin_receivers();
isa_ok $btc_list, 'Net::Stripe::List',
'Bitcoin receivers List object returned';
}
}

done_testing();