|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\Tithely\Message; |
|
4
|
|
|
|
|
5
|
|
|
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Abstract Request |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
abstract class AbstractRequest extends BaseAbstractRequest |
|
12
|
|
|
{ |
|
13
|
|
|
protected $liveEndpoint = 'https://tithe.ly/api/v1'; |
|
14
|
|
|
protected $testEndpoint = 'https://tithelydev.com/api/v1'; |
|
15
|
|
|
|
|
16
|
|
|
public function getPublicKey() |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->getParameter('publicKey'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function setPublicKey($value) |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->setParameter('publicKey', $value); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getPrivateKey() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->getParameter('privateKey'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function setPrivateKey($value) |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->setParameter('privateKey', $value); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getOrganizationId() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->getParameter('organizationId'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function setOrganizationId($value) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->setParameter('organizationId', $value); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getGivingType() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->getParameter('givingType'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setGivingType($value) |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->setParameter('givingType', $value); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function sendData($data) |
|
57
|
|
|
{ |
|
58
|
|
|
$url = $this->getEndpoint(); |
|
59
|
|
|
$httpResponse = $this->httpClient->post( |
|
60
|
|
|
$url, |
|
61
|
|
|
null, |
|
62
|
|
|
$data, |
|
63
|
|
|
array( |
|
64
|
|
|
'auth' => array($this->getPublicKey(), $this->getPrivateKey()) |
|
65
|
|
|
) |
|
66
|
|
|
)->send(); |
|
67
|
|
|
|
|
68
|
|
|
return $this->createResponse($httpResponse->json()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getOrganization() |
|
72
|
|
|
{ |
|
73
|
|
|
$httpResponse = $this->httpClient->get( |
|
74
|
|
|
self::getEndpoint() . '/organizations/' . $this->getOrganizationId(), |
|
75
|
|
|
null, |
|
76
|
|
|
array( |
|
77
|
|
|
'auth' => array($this->getPublicKey(), $this->getPrivateKey()) |
|
78
|
|
|
) |
|
79
|
|
|
)->send(); |
|
80
|
|
|
|
|
81
|
|
|
return $this->createResponse($httpResponse->json()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function getEndpoint() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function createResponse($data) |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->response = new Response($this, $data); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|