Created
February 7, 2022 19:41
-
-
Save straversi/e58aa7e0df10dc4596d216cd2962a947 to your computer and use it in GitHub Desktop.
How to make a donation in PHP
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
<?php | |
function make_donation() { | |
// TODO: Set these values. | |
// `amount` The amount of the donation in cents. | |
// `public_key` Get this from https://api.getchange.io/developers. Test key starts with pk_test, Prod key starts with pk_live. | |
// `secret_key` Get this from https://api.getchange.io/developers. Test key starts with sk_test, Prod key starts with sk_live. | |
// `nonprofit_id` Get this from https://api.getchange.io/nonprofits. When you search a nonprofit, you can see its nonprofit_id. | |
$amount = 500; | |
$public_key = ''; | |
$secret_key = ''; | |
$nonprofit_id = ''; | |
// Prepare the donation | |
$url = 'https://api.getchange.io/api/v1/donations'; | |
$data = array('amount' => $amount, 'nonprofit_id' => $nonprofit_id, 'funds_collected' => false); | |
$options = array( | |
'http' => array( | |
'header' => array("Content-type: application/json", "Authorization: Basic " . base64_encode($public_key . ":" . $secret_key)), | |
'method' => 'POST', | |
'content' => json_encode($data) | |
) | |
); | |
// Send the donation. | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
// You can inspect the response to make sure it succeeded. | |
$donation_id = json_decode($result, true)['id']; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment