Last active
February 2, 2016 11:46
-
-
Save harshals/ddef9c911c71e5a46b57 to your computer and use it in GitHub Desktop.
instamojo api using perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use JSON::MaybeXS qw/decode_json encode_json/; | |
use Mojo::UserAgent; | |
my $ua = Mojo::UserAgent->new; | |
my $params = { | |
purpose => 'some purpose', | |
amount => 100 | |
}; | |
my $tx = $ua->build_tx(POST => "https://www.instamojo.com/api/1.1/payment-requests/", form => $params ); | |
$tx->req->headers->header('X-Api-Key' => "your key"); | |
$tx->req->headers->header('X-Auth-Token' => "your token" ); | |
$tx = $ua->start($tx); | |
if (my $res = $tx->success) { | |
my $json = decode_json($res->body); | |
return $json->{payment_request}->{id}; | |
} else { | |
my $err = $tx->error; | |
say "$err->{code} response: $err->{message}" if $err->{code}; | |
say "Connection error: $err->{message}"; | |
return $err->{message}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment