Last active
August 29, 2015 14:02
-
-
Save 0x07dc/c99405f0d42fa47d76e4 to your computer and use it in GitHub Desktop.
A function to send a request for payment through Venmo, based on http://davidwalsh.name/curl-post and using the Venmo API
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
function sendPaymentRequest($email,$amount){ | |
//http://davidwalsh.name/curl-post | |
//set POST variables | |
$url = 'https://api.venmo.com/v1/payments'; | |
$access_token = ; // use your access token | |
$phone = $email; // This is email address, phone number, or user id (I think -- email addresses are common) | |
$note = "This is a request for a payment of $".$amount." for ..."; | |
$amount = $amount; | |
$audience = 'private';// chose audience | |
$fields = array( | |
'access_token' => urlencode($access_token), | |
'phone' => urlencode($phone), | |
'note' => urlencode($note), | |
'amount' => urlencode($amount), | |
'audience' => urlencode($audience) | |
); | |
//url-ify the data for the POST | |
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } | |
rtrim($fields_string, '&'); | |
//open connection | |
$ch = curl_init(); | |
//set the url, number of POST vars, POST data | |
curl_setopt($ch,CURLOPT_URL, $url); | |
curl_setopt($ch,CURLOPT_POST, count($fields)); | |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); | |
//execute post | |
$result = curl_exec($ch); | |
//close connection | |
curl_close($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment