-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspec.php
70 lines (57 loc) · 2.8 KB
/
spec.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
<?php
include 'init.php';
$client = new \ProcessOut\ProcessOut('test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x',
'key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB');
// Create and fetch a new invoice
$invoice = $client->newInvoice(array(
'name' => 'Test invoice',
'amount' => '9.99',
'currency' => 'USD',
'shipping' => new \ProcessOut\InvoiceShipping($client, array(
'address1' => 'test'
))
))->create();
assert(!empty($invoice->getId()), 'The invoice ID should not be empty');
assert(!empty($invoice->getShipping()), 'The invoice shipping info is empty');
assert($invoice->getShipping()->getAddress1() == 'test', 'The invoice shipping address1 isnt test');
$fetched = $client->newInvoice()->find($invoice->getId());
assert(!empty($fetched->getId()), 'The fetched invoice ID should not be empty');
assert($invoice->getId() == $fetched->getId(), 'The invoices ID should be equal');
// Capture an invoice
$gr = new \ProcessOut\GatewayRequest('sandbox');
$gr->url = 'https://processout.com?token=test-valid';
$gr->method = 'POST';
$gr->headers = array('Content-Type' => 'application/json');
$gr->body = '{}';
$gr->gatewayConfigurationID = 'gway_conf_44ae90db0a62f819a404ef6a8ff994ca';
$transaction = $invoice->capture($gr->getString());
assert($transaction->getStatus() == 'completed', 'The transactions status was not completed');
// Expand the transaction gateway configuration
$transaction = $transaction->find($transaction->getId(), array(
'expand' => array('gateway_configuration')
));
assert(!empty($transaction->getGatewayConfiguration()->getId()), 'The transaction gateway configuration ID was empty');
// Fetch the customers
$customers = $client->newCustomer()->all();
// Create a subscription for a customer
$customer = $client->newCustomer()->create();
assert(!empty($customer->getId()), 'The created customer ID should not be empty');
$subscription = $client->newSubscription(array(
'customer_id' => $customer->getId(),
'amount' => '9.99',
'currency' => 'USD',
'interval' => '1d',
'name' => 'great subscription'
))->create();
assert(!empty($subscription->getId()), 'The created subscription ID should not be empty');
// Expand a customers' project and fetch gateways
$customer = $client->newCustomer()->create(array('expand' => array('project')));
assert(!empty($customer->getProject()), 'The customer project should be expanded');
assert(!empty($customer->getProject()->getId()), 'The customer project ID should be expanded');
// Make sure the error code is correctly fetched
try {
$client->newCustomer()->find('bad');
assert(false, 'There should have been an error');
} catch(\ProcessOut\Exceptions\NotFoundException $e) {
assert($e->getCode() == 'resource.customer.not-found', 'The error code was incorrect');
}