public function testCreatePayout() { $currency = $this->getMockCurrency(); $currency->method('getCode')->will($this->returnValue('USD')); $token = $this->getMockToken(); $payout = new \Bitpay\Payout(); $payout->setCurrency($currency)->setEffectiveDate("1415853007000")->setPricingMethod('bitcoinbestbuy')->setNotificationUrl('https://bitpay.com')->setNotificationEmail('*****@*****.**')->setPricingMethod('bitcoinbestbuy')->setReference('your reference, can be json')->setAmount(5625)->setToken($token); $btc_amounts = array(\Bitpay\PayoutInstruction::STATUS_UNPAID => null, \Bitpay\PayoutInstruction::STATUS_PAID => '0'); $instruction0 = new \Bitpay\PayoutInstruction(); $instruction0->setId('Sra19AFU57Rx53rKQbbRKZ')->setAmount(1875)->setLabel('2')->setStatus(\Bitpay\PayoutInstruction::STATUS_UNPAID)->setBtc($btc_amounts)->setAddress('mzzsJ8G9KBmHPPVYaMxpYRetWRRec78FvF'); $instruction1 = new \Bitpay\PayoutInstruction(); $instruction1->setId('5SCdU1xNsEwrUFqKChYuAR')->setAmount(1875)->setLabel('3')->setStatus(\Bitpay\PayoutInstruction::STATUS_UNPAID)->setBtc($btc_amounts)->setAddress('mre3amN8KCFuy7gWCjhFXjuqkmoJMkd2gx'); $instruction2 = new \Bitpay\PayoutInstruction(); $instruction2->setId('5cHNbnmNuo8gRawnrFZsPy')->setAmount(1875)->setLabel('4')->setStatus(\Bitpay\PayoutInstruction::STATUS_UNPAID)->setBtc($btc_amounts)->setAddress('mre3amN8KCFuy7gWCjhFXjuqkmoJMkd2gx'); $payout->addInstruction($instruction0)->addInstruction($instruction1)->addInstruction($instruction2); $response = $this->getMockResponse(); $response->method('getBody')->willReturn(file_get_contents(__DIR__ . '/../../DataFixtures/payouts/7m7hSF3ws1LhnWUf17CXsJ.json')); $adapter = $this->getMockAdapter(); $adapter->method('sendRequest')->willReturn($response); $this->client->setAdapter($adapter); $payout = $this->client->createPayout($payout); $this->assertInstanceOf('Bitpay\\PayoutInterface', $payout); $this->assertEquals('7m7hSF3ws1LhnWUf17CXsJ', $payout->getId()); $this->assertEquals('Lwbnf9XAPCxDmy8wsRH3ct', $payout->getAccountId()); $this->assertEquals(\Bitpay\Payout::STATUS_NEW, $payout->getStatus()); $this->assertEquals(5625, $payout->getAmount()); $this->assertEquals(null, $payout->getRate()); $this->assertEquals(null, $payout->getBtcAmount()); $this->assertEquals('bitcoinbestbuy', $payout->getPricingMethod()); $this->assertEquals('your reference, can be json', $payout->getReference()); $this->assertEquals('1415853007000', $payout->getEffectiveDate()); $this->assertEquals('https://bitpay.com', $payout->getNotificationUrl()); $this->assertEquals('*****@*****.**', $payout->getNotificationEmail()); $this->assertEquals('8mZ37Gt91Wr7GXGPnB9zj1zwTcLGweRDka4axVBPi9Uxiiv7zZWvEKSgmFddQZA1Jy', $payout->getResponseToken()); $instructions = $payout->getInstructions(); $this->assertSame($instruction0, $instructions[0]); $this->assertSame($instruction1, $instructions[1]); $this->assertSame($instruction2, $instructions[2]); }
/** * 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. */ require __DIR__ . '/../vendor/autoload.php'; $time = gmdate("Y-m-d\\TH:i:s\\.", 1414691179) . "000Z"; $token = new \Bitpay\Token(); $token->setFacade('payroll')->setToken('<your payroll facade-enable token>'); //this is a special api that requires a explicit payroll relationship with BitPay $instruction1 = new \Bitpay\PayoutInstruction(); $instruction1->setAmount(100)->setAddress('2NA5EVH9HHHhM5RxSEWf54gP4v397EmFTxi')->setLabel('Paying Chris'); $payout = new \Bitpay\Payout(); $payout->setEffectiveDate($time)->setAmount(100)->setCurrency(new \Bitpay\Currency('USD'))->setPricingMethod('bitcoinbestbuy')->setReference('a reference, can be json')->setNotificationEmail('*****@*****.**')->setNotificationUrl('https://example.com/ipn.php')->setToken($token)->addInstruction($instruction1); $private = new \Bitpay\PrivateKey(); $private->setHex('662be90968bc659873d723374213fa5bf7a30c24f0f0713aa798eb7daa7230fc'); //this is your private key in some form (see GetKeys.php) $public = new \Bitpay\PublicKey(); $public->generate($private); $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);
/** * @inheritdoc */ public function getPayout($payoutId) { $request = $this->createNewRequest(); $request->setMethod(Request::METHOD_GET); $request->setPath(sprintf('payouts/%s?token=%s', $payoutId, $this->token->getToken())); $this->addIdentityHeader($request); $this->addSignatureHeader($request); $this->request = $request; $this->response = $this->sendRequest($this->request); $body = json_decode($this->response->getBody(), true); if (empty($body['data'])) { throw new \Exception('Error with request: no data returned'); } $data = $body['data']; $payout = new \Bitpay\Payout(); $payout->setId($data['id'])->setAccountId($data['account'])->setStatus($data['status'])->setCurrency(new \Bitpay\Currency($data['currency']))->setRate(@$data['rate'])->setAmount($data['amount'])->setBtcAmount(@$data['btc'])->setPricingMethod(@$data['pricingMethod'])->setReference(@$data['reference'])->setNotificationEmail(@$data['notificationEmail'])->setNotificationUrl(@$data['notificationURL'])->setRequestDate($data['requestDate'])->setEffectiveDate($data['effectiveDate'])->setResponseToken($data['token']); array_walk($data['instructions'], function ($value, $key) use(&$payout) { $instruction = new \Bitpay\PayoutInstruction(); $instruction->setId($value['id'])->setLabel($value['label'])->setAddress($value['address'])->setStatus($value['status'])->setAmount($value['amount'])->setBtc($value['btc']); array_walk($value['transactions'], function ($value, $key) use(&$instruction) { $transaction = new \Bitpay\PayoutTransaction(); $transaction->setTransactionId($value['txid'])->setAmount($value['amount'])->setDate($value['date']); $instruction->addTransaction($transaction); }); $payout->addInstruction($instruction); }); return $payout; }
/** * Copyright (c) 2014-2015 BitPay */ /** * WARNING - This example will NOT work until you have generated your public * and private keys. Please see the example documentation on generating your * 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. */ require __DIR__ . '/../vendor/autoload.php'; $time = gmdate("Y-m-d\\TH:i:s\\.", 1414691179) . "000Z"; $token = new \Bitpay\Token(); $token->setFacade('payroll')->setToken('your token here'); $instruction1 = new \Bitpay\PayoutInstruction(); $instruction1->setAmount(990)->setAddress('n3Sx4askJeykUYk24sS5rQoCEm8BpwVrNg')->setLabel('Paying Tom'); $instruction2 = new \Bitpay\PayoutInstruction(); $instruction2->setAmount(1490)->setAddress('mxRN6AQJaDi5R6KmvMaEmZGe3n5ScV9u33')->setLabel('Paying Harry'); $payout = new \Bitpay\Payout(); $payout->setEffectiveDate($time)->setCurrency(new \Bitpay\Currency('USD'))->setPricingMethod('bitcoinbestbuy')->setReference('a reference, can be json')->setNotificationEmail('*****@*****.**')->setNotificationUrl('https://yoursite.com/callback')->setToken($token)->addInstruction($instruction1)->addInstruction($instruction2); /** * Create a new client. You can see the example of how to configure this using * a yml file as well. */ $bitpay = new \Bitpay\Bitpay(array('bitpay' => array('network' => 'testnet', 'public_key' => getenv('HOME') . '/.bitpayphp/api.pub', 'private_key' => getenv('HOME') . '/.bitpayphp/api.key', 'key_storage' => 'Bitpay\\Storage\\FilesystemStorage'))); /** * Create the client that will be used to send requests to BitPay's API */ $client = $bitpay->get('client'); $client->createPayout($payout);