Business-OnlinePayment-BitPay-Client

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Business::OnlinePayment::BitPay::KeyUtils" : "0",
            "Carp" : "0",
            "HTTP::Request" : "0",
            "IO::Socket::SSL" : "0",
            "JSON" : "0",
            "JSON::Parse" : "0",
            "LWP::Protocol::https" : "0",
            "LWP::UserAgent" : "0",
            "Mozilla::CA" : "0",
            "Net::SSLeay" : "0",
            "String::Interpolate" : "0",
            "Test::BDD::Cucumber::Loader" : "0",
            "Test::BDD::Cucumber::StepFile" : "0",
            "Test::Exception" : "0",

META.yml  view on Meta::CPAN

  version: '1.4'
name: Business-OnlinePayment-BitPay-Client
no_index:
  directory:
    - t
    - inc
requires:
  Business::OnlinePayment::BitPay::KeyUtils: '0'
  Carp: '0'
  HTTP::Request: '0'
  IO::Socket::SSL: '0'
  JSON: '0'
  JSON::Parse: '0'
  LWP::Protocol::https: '0'
  LWP::UserAgent: '0'
  Mozilla::CA: '0'
  Net::SSLeay: '0'
  String::Interpolate: '0'
  Test::BDD::Cucumber::Loader: '0'
  Test::BDD::Cucumber::StepFile: '0'
  Test::Exception: '0'

Makefile.PL  view on Meta::CPAN

    VERSION_FROM    => 'lib/Business/OnlinePayment/BitPay/Client.pm',
    PREREQ_PM       => {
        'Carp' => '0',
        'Mozilla::CA' => '0',
        'LWP::UserAgent' => '0',
        'HTTP::Request' => '0',
        'LWP::Protocol::https' => '0',
        'Business::OnlinePayment::BitPay::KeyUtils' => '0',
        'JSON' => '0',
        'JSON::Parse' => '0',
        'IO::Socket::SSL' => '0',
        'Net::SSLeay' => '0',
        'Test::Exception' => '0',
        'Test::Fake::HTTPD' => '0',
        'String::Interpolate' => '0',
        'Test::BDD::Cucumber::Loader' => '0',
        'Test::BDD::Cucumber::StepFile' => '0'
    },
    ABSTRACT       => 'Fast, flexible connector for the BitPay API',
    AUTHOR         => 'Paul Daigle',
    LICENSE        => 'mit'

lib/Business/OnlinePayment/BitPay/Client.pm  view on Meta::CPAN


use Carp;
use warnings;
use Mozilla::CA;
use LWP::UserAgent;
use HTTP::Request;
use LWP::Protocol::https;
use Business::OnlinePayment::BitPay::KeyUtils;
use JSON;
use JSON::Parse 'parse_json';
require IO::Socket::SSL;
use Net::SSLeay;
use Data::Dumper;

sub new {
    my $class = shift;
    my %opts = @_;
    my $pem = $opts{"pem"}
        or croak "no pem passed to constructor";
    my $apiUri = "https://bitpay.com";
    my $id = Business::OnlinePayment::BitPay::KeyUtils::bpGenerateSinFromPem($pem);

lib/Business/OnlinePayment/BitPay/Client.pm  view on Meta::CPAN

    $request->content($jsonc);
    $request->header('content-type' => 'application/json');
    $request->header('X-BitPay-Plugin-Info' => 'PerlLib');
    $request->header('User-Agent' => 'perl-bitpay-client');
    unless($public){
        my $signature = Business::OnlinePayment::BitPay::KeyUtils::bpSignMessageWithPem($self->{pem}, $uri); 
        my $pubkey = Business::OnlinePayment::BitPay::KeyUtils::bpGetPublicKeyFromPem($self->{pem});
        $request->header('X-Signature' => $signature, 'X-Identity' => $pubkey);
    }
    my $ua = LWP::UserAgent->new;
    $ua->ssl_opts( verify_hostname=> 0, SSL_ca_file => Mozilla::CA::SSL_ca_file(), SSL_Version => 'TLSv2', SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE);
    my $response = $ua->request($request);
    return $response if $response->is_success;
    my $code = $response->code;
    my $error = decode_json($response->content)->{'error'};
    croak "$code: $error"; 
}

sub post{
    my $self = shift;
    my %opts = @_;
    my $path = $opts{"path"};
    my %content = %{%opts->{"params"}};
    my $uri = $self->{apiUri} or croak "no api_uri exists for object";
    $uri = $uri . "/" . $path;
    my $request = HTTP::Request->new(POST => $uri);
    my $ua = LWP::UserAgent->new;
    $ua->ssl_opts( verify_hostname=> 0, SSL_ca_file => Mozilla::CA::SSL_ca_file(), SSL_Version => 'TLSv2', SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE);
    my $jsonc = encode_json \%content;
    $request->content($jsonc);
    $request->header('content-type' => 'application/json');
    $request->header('X-BitPay-Plugin-Info' => 'PerlLib');
    $request->header('User-Agent' => 'perl-bitpay-client');
    if ($content{"token"}){
        my $signature = Business::OnlinePayment::BitPay::KeyUtils::bpSignMessageWithPem($self->{pem}, $uri . $jsonc);
        my $pubkey = Business::OnlinePayment::BitPay::KeyUtils::bpGetPublicKeyFromPem($self->{pem});
        $request->header('X-Signature' => $signature, 'X-Identity' => $pubkey);
    }



( run in 0.483 second using v1.01-cache-2.11-cpan-4d50c553e7e )