1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\Tithely\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\Exception\InvalidRequestException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Purchase Request |
9
|
|
|
* |
10
|
|
|
* @method Response send() |
11
|
|
|
*/ |
12
|
|
|
class PurchaseRequest extends AbstractRequest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Validate the currency. |
16
|
|
|
* |
17
|
|
|
* This method checks a currency against the Tithe.ly organization's |
18
|
|
|
* bank account configuration. |
19
|
|
|
* |
20
|
|
|
* @param string $currency |
21
|
|
|
* @throws InvalidRequestException |
22
|
|
|
*/ |
23
|
|
|
private function validateCurrency($currency) |
24
|
|
|
{ |
25
|
|
|
$organization = $this->getOrganization(); |
26
|
|
|
$data = $organization->getData(); |
27
|
|
|
|
28
|
|
|
if (!isset($data['object']['bank']['currency'])) { |
29
|
|
|
throw new InvalidRequestException('Could not fetch organization.'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if ($data['object']['bank']['currency'] != $currency) { |
33
|
|
|
throw new InvalidRequestException('The organization does not support payments made in ' . $currency . '.'); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getData() |
38
|
|
|
{ |
39
|
|
|
$this->validate('token', 'amount', 'currency', 'card'); |
40
|
|
|
$this->validateCurrency($this->getCurrency()); |
41
|
|
|
|
42
|
|
|
$data = array( |
43
|
|
|
'first_name' => $this->getCard()->getFirstName(), |
44
|
|
|
'last_name' => $this->getCard()->getLastName(), |
45
|
|
|
'email' => $this->getCard()->getEmail(), |
46
|
|
|
'token' => $this->getParameter('token'), |
47
|
|
|
'organization_id' => $this->getOrganizationId(), |
48
|
|
|
'amount' => $this->getAmountInteger(), |
49
|
|
|
'giving_type' => $this->getGivingType() |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
return $data; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getEndpoint() |
56
|
|
|
{ |
57
|
|
|
return parent::getEndpoint() . '/charge-once'; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|