This repository was archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathCreateInvoice.php
95 lines (83 loc) · 2.34 KB
/
CreateInvoice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* 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';
/**
* Create an Item object that will be used later
*/
$item = new \Bitpay\Item();
$item
->setCode('skuNumber')
->setDescription('General Description of Item')
->setPrice('1.99');
/**
* Create Buyer object that will be used later.
*/
$buyer = new \Bitpay\Buyer();
$buyer
->setFirstName('Some')
->setLastName('Customer')
->setPhone('555-5555-5555')
->setEmail('[email protected]')
->setAddress(
array(
'123 Main St',
'Suite 1',
)
)
->setCity('Atlanta')
->setState('GA')
->setZip('30120')
->setCountry('US');
/**
* Create the invoice
*/
$invoice = new \Bitpay\Invoice();
// Add the item to the invoice
$invoice->setItem($item);
// Add the buyers info to invoice
$invoice->setBuyer($buyer);
// Configure the rest of the invoice
$invoice
->setOrderId('OrderIdFromYourSystem')
// You will receive IPN's at this URL, should be HTTPS for security purposes!
->setNotificationUrl('https://store.example.com/bitpay/callback');
/**
* BitPay offers services for many different currencies. You will need to
* configure the currency in which you are selling products with.
*/
$currency = new \Bitpay\Currency();
$currency->setCode('USD');
// Set the invoice currency
$invoice->setCurrency($currency);
/**
* Create a new client. You can see the example of how to configure this using
* a yml file as well.
*/
$bitpay = new \Bitpay\Bitpay(__DIR__ . '/config.yml');
/**
* Create the client that will be used to send requests to BitPay's API
*/
$client = $bitpay->get('client');
/**
* You will need to set the token that was returned when you paired your
* keys.
*/
$token = new \Bitpay\Token();
$token->setToken('your token here');
$client->setToken($token);
// Send invoice
$client->createInvoice($invoice);
var_dump(
(string) $client->getRequest(),
(string) $client->getResponse(),
$invoice
);