Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #306 from thejoshualewis/invite-users
Browse files Browse the repository at this point in the history
added example to invite users
  • Loading branch information
thejoshualewis committed Jan 22, 2021
2 parents ca7fe2c + 14c1c2e commit bac676d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
54 changes: 54 additions & 0 deletions examples/tutorial/006_Emails.php
@@ -0,0 +1,54 @@
<?php
/**
* Copyright (c) 2014-2015 BitPay
*/

/**
* WARNING - This example will NOT work until you have generated your public
* keys and also see the documentation on how to save those keys.
*
* Also please be aware that you CANNOT create an invoice until you have paired
* the keys and received a token back. The token is usesd with the request.
*/

$key_dir = '/tmp';
require __DIR__.'/../../vendor/autoload.php';

$time = gmdate("Y-m-d\TH:i:s\.", 1414691179)."000Z";

$token = "<your api token>";

//this is your private key in some form (see GetKeys.php)
$storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('TopSecretPassword');
$private = $storageEngine->load($key_dir . '/bitpay.pri');
$public = $storageEngine->load($key_dir . '/bitpay.pub');

$network = new \Bitpay\Network\Testnet();
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();


$bitpay = new \Bitpay\Bitpay();

$client = new \Bitpay\Client\Client();
$client->setPrivateKey($private);
$client->setPublicKey($public);
$client->setNetwork($network);
$client->setAdapter($adapter);

#create a batch of email addresses to invite to create a BitPay account

$emails[] =
array(
"email"=>"email-address1@email.com",
"notificationURL" =>"https://test.com/ipn",
"label"=>"email test 1"
);

$emails[] =
array(
"email"=>"email-address2@email.com",
"notificationURL" =>"https://test.com/ipn",
"label"=>"email test 2"
);
$response = $client->createRecipient($token,$emails);
print_r($response);
27 changes: 25 additions & 2 deletions src/Bitpay/Client/Client.php
Expand Up @@ -209,6 +209,8 @@ public function createInvoice(InvoiceInterface $invoice)
/**
* @inheritdoc
*/


public function getCurrencies()
{
$this->request = $this->createNewRequest();
Expand Down Expand Up @@ -238,11 +240,33 @@ public function getCurrencies()
return $currencies;
}

public function createRecipient($token,$recipients)
{
$request = $this->createNewRequest();
$request->setMethod($request::METHOD_POST);
$request->setPath('recipients');
$body = array(
'token' => $token,
'recipients' =>
$recipients
);
$request->setBody(json_encode($body));
$this->addIdentityHeader($request);
$this->addSignatureHeader($request);

$this->request = $request;

$this->response = $this->sendRequest($request);
$body = json_decode($this->response->getBody(), true);
return $body;
}

/**
* @inheritdoc
*/
public function createPayout(PayoutInterface $payout)
{

$request = $this->createNewRequest();
$request->setMethod($request::METHOD_POST);
$request->setPath('payouts');
Expand Down Expand Up @@ -276,10 +300,9 @@ public function createPayout(PayoutInterface $payout)
$body['instructions'][] = array(
'label' => $instruction->getLabel(),
'address' => $instruction->getAddress(),
'amount' => $instruction->getAmount()
'amount' => $instruction->getAmount(),
);
}

$request->setBody(json_encode($body));
$this->addIdentityHeader($request);
$this->addSignatureHeader($request);
Expand Down

0 comments on commit bac676d

Please sign in to comment.