I come out of the depths with a curl. I want to integrate PayMill into my website (which is written in Perl). There is no Perl lib for Paymill yet, so I need to connect to them via curl.
I completed JS Paymill front-end integration and received a payment token from PayMill.
Now I need to transfer the token received from Paymill to my backend and use the curl to ask PayMill to complete the transaction and charge the user. At this moment I am stuck.
To make the transaction, the PayMill documentation says that I have to do the following:
curl https://api.paymill.de/v2/transactions \ -u b94a7550bd908877cbae5d3cf0dc4b74: \ -d "amount=4200" \ -d "currency=EUR" \ -d "token=098f6bcd4621d373cade4e832627b4f6" \ -d "description=Test Transaction"
I believe this is a Paymill secret key to authenticate my request, although the documentation is not clear here.
I looked at WWW :: Curl :: Easy, Net: Curl :: Easy and LWP :: Curl, however, nothing in the documentation for these methods showed me how to form the request above.
I tried (not believing this would work) by simply encoding the string in perl, as described above;
my $request = '-u ' . $private_key . " "; foreach my $key (keys %$params_in) { $request .= '-d "' . lc($key) .'='.$params_in->{$key} . ' '; }
And then passing $ request to my attempt to curl like this:
my $curl = WWW::Curl::Easy->new; $curl->setopt(WWW::Curl::Easy::CURLOPT_HEADER(), 1); $curl->setopt(WWW::Curl::Easy::CURLOPT_URL(), $paymill_server); $curl->setopt(WWW::Curl::Easy::CURLOPT_POST(), 1); $curl->setopt(WWW::Curl::Easy::CURLOPT_POSTFIELDS(), $request); my $response; $curl->setopt(WWW::Curl::Easy::CURLOPT_WRITEDATA(), \$response); my $retcode = $curl->perform;
however, what about the Access Denied error, which I believe is an error because Paymill cannot find my key, because I am confusing Curl (assuming that -u should be secret_key).
I feel that something is missing here.
Can someone point me in the right direction how to do this? Thanks
UPDATE
Excellent answers, thank you all for your help, it is working now. In the end, I went with the Matthias solution, and the final complete transaction solution was as follows:
use LWP::UserAgent; use MIME::Base64; use JSON::XS; my $ua = LWP::UserAgent->new; $ua->default_header(Authorization => "Basic " . encode_base64(private_key)); my $response = $ua->post(https://api.paymill.de:443/v2/transactions , $params ); if ( $response->is_success ) { my $obj = eval { decode_json $response->content } || {}; etc }