Skip to content

Commit 8feb0c8

Browse files
committed
Payout function added
1 parent b940fb1 commit 8feb0c8

File tree

8 files changed

+596
-1
lines changed

8 files changed

+596
-1
lines changed

src/Omnipay/Paysafecard/Gateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ public function completePurchase(array $parameters = array())
105105
return $this->createRequest('\Omnipay\Paysafecard\Message\CompletePurchaseRequest', $parameters);
106106
}
107107

108+
/**
109+
* @param array $parameters
110+
*
111+
* @return \Omnipay\Paysafecard\Message\PayoutRequest
112+
*/
113+
public function payout(array $parameters = array())
114+
{
115+
return $this->createRequest('\Omnipay\Paysafecard\Message\PayoutRequest', $parameters);
116+
}
117+
108118
/**
109119
* @param array $parameters
110120
*
Lines changed: 359 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,359 @@
1+
<?php
2+
3+
namespace Omnipay\Paysafecard\Message;
4+
5+
use Omnipay\Common\Exception\InvalidResponseException;
6+
7+
/**
8+
* Paysafecard Payout Request.
9+
*
10+
* @author Alexander Fedra <[email protected]>
11+
* @copyright 2015 DerCoder
12+
* @license http://opensource.org/licenses/mit-license.php MIT
13+
*
14+
* @version 1.4 Paysafecard Payout API Specification
15+
*/
16+
class PayoutRequest extends AbstractRequest
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
protected function getMethod()
22+
{
23+
return 'payout';
24+
}
25+
26+
/**
27+
* Get the customer's email address.
28+
*
29+
* Related value to the customerIdType
30+
* Max. length: 90 characters
31+
* The e-mail address of the customer
32+
*
33+
* @return string email
34+
*/
35+
public function getEmail()
36+
{
37+
return $this->getParameter('email');
38+
}
39+
40+
/**
41+
* Set the customer's email address.
42+
*
43+
* Related value to the customerIdType
44+
* Max. length: 90 characters
45+
* The e-mail address of the customer
46+
*
47+
* @param string $value email
48+
*
49+
* @return self
50+
*/
51+
public function setEmail($value)
52+
{
53+
return $this->setParameter('email', $value);
54+
}
55+
56+
/**
57+
* Get the client merchant ID.
58+
*
59+
* A unique end customer identifier (the unique ID of the end customer as registered at the
60+
* merchant’s database)
61+
* NOTE: for security reasons do not use the customer‘s registered username, unless encrypted.
62+
* max. length: 50 characters
63+
* example: client123
64+
*
65+
* @return string client merchant id
66+
*/
67+
public function getClientMerchantId()
68+
{
69+
return $this->getParameter('clientMerchantId');
70+
}
71+
72+
/**
73+
* Set the client merchant ID.
74+
*
75+
* A unique end customer identifier (the unique ID of the end customer as registered at the
76+
* merchant’s database)
77+
* NOTE: for security reasons do not use the customer‘s registered username, unless encrypted.
78+
* max. length: 50 characters
79+
* example: client123
80+
*
81+
* @param string $value client merchant id
82+
*
83+
* @return self
84+
*/
85+
public function setClientMerchantId($value)
86+
{
87+
return $this->setParameter('clientMerchantId', $value);
88+
}
89+
90+
/**
91+
* Set validation only setting.
92+
*
93+
* Validate the payout without actually transferring the funds
94+
* value true: Test the payout
95+
* value false: to execute payout
96+
*
97+
* @return string validation only
98+
*/
99+
public function getValidationOnly()
100+
{
101+
$value = $this->getParameter('validationOnly');
102+
103+
return $value === true ? 'true' : 'false';
104+
}
105+
106+
/**
107+
* Get validation only setting.
108+
*
109+
* Validate the payout without actually transferring the funds
110+
* value true: Test the payout
111+
* value false: to execute payout
112+
*
113+
* @param bool $value validation only
114+
*
115+
* @return self
116+
*/
117+
public function setValidationOnly($value)
118+
{
119+
return $this->setParameter('validationOnly', $value);
120+
}
121+
122+
/**
123+
* Set UTC offset.
124+
*
125+
* The difference in hours and minutes from Coordinated Universal Time (UTC)
126+
* example: -03:00
127+
*
128+
* @return string UTC offset
129+
*/
130+
public function getUtcOffset()
131+
{
132+
$value = $this->getParameter('utcOffset');
133+
134+
return $value ? $value : '+00:00';
135+
}
136+
137+
/**
138+
* Get UTC offset.
139+
*
140+
* The difference in hours and minutes from Coordinated Universal Time (UTC)
141+
* example: -03:00
142+
*
143+
* @param string $value UTC offset
144+
*
145+
* @return self
146+
*/
147+
public function setUtcOffset($value)
148+
{
149+
return $this->setParameter('utcOffset', $value);
150+
}
151+
152+
/**
153+
* Get the customer's first name.
154+
*
155+
* The first name of the payout customer
156+
* example: John
157+
* max. length. 40 characters
158+
*
159+
* @return string first name
160+
*/
161+
public function getFirstName()
162+
{
163+
return $this->getParameter('firstName');
164+
}
165+
166+
/**
167+
* Set the customer's first name.
168+
*
169+
* The first name of the payout customer
170+
* example: John
171+
* max. length. 40 characters
172+
*
173+
* @param string $value first name
174+
*
175+
* @return self
176+
*/
177+
public function setFirstName($value)
178+
{
179+
return $this->setParameter('firstName', $value);
180+
}
181+
182+
/**
183+
* Get the customer's last name.
184+
*
185+
* The last name of the payout customer
186+
* example: Do
187+
* max. length. 40 characters
188+
*
189+
* @return string last name
190+
*/
191+
public function getLastName()
192+
{
193+
return $this->getParameter('lastName');
194+
}
195+
196+
/**
197+
* Set the customer's last name.
198+
*
199+
* The last name of the payout customer
200+
* example: Do
201+
* max. length. 40 characters
202+
*
203+
* @param string $value last name
204+
*
205+
* @return self
206+
*/
207+
public function setLastName($value)
208+
{
209+
return $this->setParameter('lastName', $value);
210+
}
211+
212+
/**
213+
* Get the customers's birthday.
214+
*
215+
* The date of birth of the payout customer in YYYY-MM-DD format
216+
* example: 1979-12-20
217+
*
218+
* @param string $format
219+
*
220+
* @return string birthday
221+
*/
222+
public function getBirthday($format = 'Y-m-d')
223+
{
224+
$value = $this->getParameter('birthday');
225+
226+
return $value ? $value->format($format) : null;
227+
}
228+
229+
/**
230+
* Sets the customers's birthday.
231+
*
232+
* The date of birth of the payout customer in YYYY-MM-DD format
233+
* example: 1979-12-20
234+
*
235+
* @param string $value
236+
*
237+
* @return self
238+
*/
239+
public function setBirthday($value)
240+
{
241+
$value = new \DateTime($value, new \DateTimeZone('UTC'));
242+
243+
return $this->setParameter('birthday', $value);
244+
}
245+
246+
/**
247+
* Get the data for this request.
248+
*
249+
* @return array request data
250+
*/
251+
public function getData()
252+
{
253+
$this->validate(
254+
'username',
255+
'password',
256+
'transactionId',
257+
'amount',
258+
'currency',
259+
'email',
260+
'clientMerchantId',
261+
'firstName',
262+
'lastName',
263+
'birthday'
264+
);
265+
266+
$document = new \DOMDocument('1.0', 'utf-8');
267+
$document->formatOutput = false;
268+
$document->createElement('soapenv:Header');
269+
270+
$envelope = $document->appendChild(
271+
$document->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv:Envelope')
272+
);
273+
$envelope->setAttribute('xmlns:urn', 'urn:pscservice');
274+
275+
$body = $envelope->appendChild(
276+
$document->createElement('soapenv:Body')
277+
);
278+
279+
$payout = $body->appendChild(
280+
$document->createElement('urn:payout')
281+
);
282+
283+
$payout->appendChild(
284+
$document->createElement('urn:username', $this->getUsername())
285+
);
286+
287+
$payout->appendChild(
288+
$document->createElement('urn:password', $this->getPassword())
289+
);
290+
291+
$payout->appendChild(
292+
$document->createElement('urn:ptid', $this->getTransactionId())
293+
);
294+
295+
$payout->appendChild(
296+
$document->createElement('urn:subId', $this->getSubId())
297+
);
298+
299+
$payout->appendChild(
300+
$document->createElement('urn:amount', $this->getAmount())
301+
);
302+
303+
$payout->appendChild(
304+
$document->createElement('urn:currency', $this->getCurrency())
305+
);
306+
307+
$payout->appendChild(
308+
$document->createElement('urn:customerIdType', 'EMAIL')
309+
);
310+
311+
$payout->appendChild(
312+
$document->createElement('urn:customerId', $this->getEmail())
313+
);
314+
315+
$payout->appendChild(
316+
$document->createElement('urn:merchantClientId', $this->getClientMerchantId())
317+
);
318+
319+
$payout->appendChild(
320+
$document->createElement('urn:validationOnly', $this->getValidationOnly())
321+
);
322+
323+
$payout->appendChild(
324+
$document->createElement('urn:utcOffset', $this->getUtcOffset())
325+
);
326+
327+
$customer = $payout->appendChild(
328+
$document->createElement('urn:customerDetailsBasic')
329+
);
330+
331+
$customer->appendChild(
332+
$document->createElement('urn:firstName', $this->getFirstName())
333+
);
334+
335+
$customer->appendChild(
336+
$document->createElement('urn:lastName', $this->getLastName())
337+
);
338+
339+
$customer->appendChild(
340+
$document->createElement('urn:dateOfBirth', $this->getBirthday())
341+
);
342+
343+
return $document->saveXML();
344+
}
345+
346+
/**
347+
* Create a proper response based on the request.
348+
*
349+
* @param \SimpleXMLElement $xml
350+
*
351+
* @return PayoutResponse
352+
*
353+
* @throws InvalidResponseException
354+
*/
355+
protected function createResponse(\SimpleXMLElement $xml)
356+
{
357+
return $this->response = new PayoutResponse($this, $xml);
358+
}
359+
}

0 commit comments

Comments
 (0)