Skip to content

Commit f18f787

Browse files
committed
Payout Validation function added
1 parent 8feb0c8 commit f18f787

12 files changed

+300
-41
lines changed

src/Omnipay/Paysafecard/Gateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ public function payout(array $parameters = array())
115115
return $this->createRequest('\Omnipay\Paysafecard\Message\PayoutRequest', $parameters);
116116
}
117117

118+
/**
119+
* @param array $parameters
120+
*
121+
* @return \Omnipay\Paysafecard\Message\ValidatePayoutRequest
122+
*/
123+
public function validatePayout(array $parameters = array())
124+
{
125+
return $this->createRequest('\Omnipay\Paysafecard\Message\ValidatePayoutRequest', $parameters);
126+
}
127+
118128
/**
119129
* @param array $parameters
120130
*

src/Omnipay/Paysafecard/Message/PayoutRequest.php

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ protected function getMethod()
2323
return 'payout';
2424
}
2525

26+
/**
27+
* {@inheritdoc}
28+
*/
29+
protected function getValidationOnly()
30+
{
31+
return 'false';
32+
}
33+
2634
/**
2735
* Get the customer's email address.
2836
*
@@ -88,39 +96,7 @@ public function setClientMerchantId($value)
8896
}
8997

9098
/**
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.
99+
* Get UTC offset.
124100
*
125101
* The difference in hours and minutes from Coordinated Universal Time (UTC)
126102
* example: -03:00
@@ -135,7 +111,7 @@ public function getUtcOffset()
135111
}
136112

137113
/**
138-
* Get UTC offset.
114+
* Set UTC offset.
139115
*
140116
* The difference in hours and minutes from Coordinated Universal Time (UTC)
141117
* example: -03:00
@@ -227,7 +203,7 @@ public function getBirthday($format = 'Y-m-d')
227203
}
228204

229205
/**
230-
* Sets the customers's birthday.
206+
* Set the customers's birthday.
231207
*
232208
* The date of birth of the payout customer in YYYY-MM-DD format
233209
* example: 1979-12-20

src/Omnipay/Paysafecard/Message/PayoutResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(RequestInterface $request, \SimpleXMLElement $data)
3232

3333
public function isSuccessful()
3434
{
35-
return $this->getErrorCode() === 0 && $this->getResultCode() === 0 && $this->getValidationOnly() === 'false';
35+
return $this->getErrorCode() === 0 && $this->getResultCode() === 0 && $this->getValidationOnly() === false;
3636
}
3737

3838
public function getCode()
@@ -64,6 +64,8 @@ public function getAmount()
6464

6565
public function getValidationOnly()
6666
{
67-
return (string) $this->data->validationOnly;
67+
$validationOnly = (string) $this->data->validationOnly;
68+
69+
return $validationOnly === 'false' ? false : true;
6870
}
6971
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 ValidatePayoutRequest extends PayoutRequest
17+
{
18+
public function getValidationOnly()
19+
{
20+
return 'true';
21+
}
22+
23+
/**
24+
* Create a proper response based on the request.
25+
*
26+
* @param \SimpleXMLElement $xml
27+
*
28+
* @return ValidatePayoutResponse
29+
*
30+
* @throws InvalidResponseException
31+
*/
32+
protected function createResponse(\SimpleXMLElement $xml)
33+
{
34+
return $this->response = new ValidatePayoutResponse($this, $xml);
35+
}
36+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Omnipay\Paysafecard\Message;
4+
5+
/**
6+
* Paysafecard Purchase Response.
7+
*
8+
* @author Alexander Fedra <[email protected]>
9+
* @copyright 2015 DerCoder
10+
* @license http://opensource.org/licenses/mit-license.php MIT
11+
*
12+
* @version 1.4 Paysafecard Payout API Specification
13+
*/
14+
class ValidatePayoutResponse extends PayoutResponse
15+
{
16+
public function isSuccessful()
17+
{
18+
return $this->getErrorCode() === 0 && $this->getResultCode() === 0 && $this->getValidationOnly() === true;
19+
}
20+
}

tests/Omnipay/Paysafecard/GatewayTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,62 @@ public function testCompletePurchase()
7272
$this->assertSame('EUR', $request->getCurrency());
7373
}
7474

75+
public function testPayout()
76+
{
77+
$request = $this->gateway->payout(array(
78+
'subId' => 'shop1',
79+
'email' => '[email protected]',
80+
'firstName' => 'John',
81+
'lastName' => 'Doe',
82+
'birthday' => '30.12.1976',
83+
'utcOffset' => '+02:00',
84+
'clientMerchantId' => 'client123',
85+
'transactionId' => 'TX9997888',
86+
'amount' => '14.65',
87+
'currency' => 'EUR'
88+
));
89+
90+
$this->assertSame('https://soatest.paysafecard.com/psc/services/PscService', $request->getEndpoint());
91+
$this->assertSame('shop1', $request->getSubId());
92+
$this->assertSame('[email protected]', $request->getEmail());
93+
$this->assertSame('John', $request->getFirstName());
94+
$this->assertSame('Doe', $request->getLastName());
95+
$this->assertSame('1976-12-30', $request->getBirthday());
96+
$this->assertSame('+02:00', $request->getUtcOffset());
97+
$this->assertSame('client123', $request->getClientMerchantId());
98+
$this->assertSame('TX9997888', $request->getTransactionId());
99+
$this->assertSame('14.65', $request->getAmount());
100+
$this->assertSame('EUR', $request->getCurrency());
101+
}
102+
103+
public function testValidatePayout()
104+
{
105+
$request = $this->gateway->validatePayout(array(
106+
'subId' => 'shop1',
107+
'email' => '[email protected]',
108+
'firstName' => 'John',
109+
'lastName' => 'Doe',
110+
'birthday' => '30.12.1976',
111+
'utcOffset' => '+02:00',
112+
'clientMerchantId' => 'client123',
113+
'transactionId' => 'TX9997888',
114+
'amount' => '14.65',
115+
'currency' => 'EUR'
116+
));
117+
118+
$this->assertSame('https://soatest.paysafecard.com/psc/services/PscService', $request->getEndpoint());
119+
$this->assertSame('shop1', $request->getSubId());
120+
$this->assertSame('[email protected]', $request->getEmail());
121+
$this->assertSame('John', $request->getFirstName());
122+
$this->assertSame('Doe', $request->getLastName());
123+
$this->assertSame('1976-12-30', $request->getBirthday());
124+
$this->assertSame('+02:00', $request->getUtcOffset());
125+
$this->assertSame('client123', $request->getClientMerchantId());
126+
$this->assertSame('TX9997888', $request->getTransactionId());
127+
$this->assertSame('14.65', $request->getAmount());
128+
$this->assertSame('EUR', $request->getCurrency());
129+
}
130+
75131
public function testFetchTransaction()
76132
{
77133
$request = $this->gateway->fetchTransaction(array(

tests/Omnipay/Paysafecard/Message/PayoutRequestTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function setUp()
2828
'firstName' => 'John',
2929
'lastName' => 'Doe',
3030
'birthday' => '30.12.1976',
31-
'validationOnly' => false,
3231
'utcOffset' => '+02:00',
3332
'clientMerchantId' => 'client123',
3433
'transactionId' => 'TX9997888',

tests/Omnipay/Paysafecard/Message/PayoutResponseTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function setUp()
1212
{
1313
parent::setUp();
1414

15-
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
15+
$this->request = new PayoutRequest($this->getHttpClient(), $this->getHttpRequest());
1616
$this->request->initialize(array(
1717
'username' => 'SOAP_USERNAME',
1818
'password' => 'oJ2rHLBVSbD5iGfT',
@@ -21,7 +21,6 @@ public function setUp()
2121
'firstName' => 'John',
2222
'lastName' => 'Doe',
2323
'birthday' => '30.12.1976',
24-
'validationOnly' => false,
2524
'utcOffset' => '+02:00',
2625
'clientMerchantId' => 'client123',
2726
'transactionId' => 'TX9997889',
@@ -53,7 +52,7 @@ public function testFailure()
5352
$this->assertSame('TX9997889', $response->getTransactionId());
5453
$this->assertSame('14.65', $response->getAmount());
5554
$this->assertSame('EUR', $response->getCurrency());
56-
$this->assertSame('false', $response->getValidationOnly());
55+
$this->assertFalse($response->getValidationOnly());
5756
}
5857

5958
public function testSuccess()
@@ -67,6 +66,9 @@ public function testSuccess()
6766
$this->assertSame(0, $response->getCode());
6867
$this->assertNull($response->getMessage());
6968
$this->assertSame('TX9997889', $response->getTransactionId());
69+
$this->assertSame('14.65', $response->getAmount());
70+
$this->assertSame('EUR', $response->getCurrency());
71+
$this->assertFalse($response->getValidationOnly());
7072
}
7173

7274
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
namespace Omnipay\Paysafecard\Message;
3+
4+
use Omnipay\Tests\TestCase;
5+
6+
class ValidatePayoutRequestTest extends TestCase
7+
{
8+
private $request;
9+
10+
public function setUp()
11+
{
12+
parent::setUp();
13+
14+
$httpResponse = $this->getMockHttpResponse('ValidatePayoutSuccess.txt');
15+
16+
$mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
17+
$mockPlugin->addResponse($httpResponse);
18+
19+
$httpClient = $this->getHttpClient();
20+
$httpClient->addSubscriber($mockPlugin);
21+
22+
$this->request = new ValidatePayoutRequest($httpClient, $this->getHttpRequest());
23+
$this->request->initialize(array(
24+
'username' => 'SOAP_USERNAME',
25+
'password' => 'oJ2rHLBVSbD5iGfT',
26+
'subId' => 'shop1',
27+
'email' => '[email protected]',
28+
'firstName' => 'John',
29+
'lastName' => 'Doe',
30+
'birthday' => '30.12.1976',
31+
'utcOffset' => '+02:00',
32+
'clientMerchantId' => 'client123',
33+
'transactionId' => 'TX9997888',
34+
'amount' => '14.65',
35+
'currency' => 'EUR'
36+
));
37+
}
38+
39+
public function testGetData()
40+
{
41+
$data = $this->request->getData();
42+
$xml = new \SimpleXMLElement($data);
43+
44+
$request = $xml
45+
->children('http://schemas.xmlsoap.org/soap/envelope/')
46+
->children('urn:pscservice')
47+
->payout;
48+
49+
$this->assertSame('SOAP_USERNAME', (string) $request->username);
50+
$this->assertSame('oJ2rHLBVSbD5iGfT', (string) $request->password);
51+
$this->assertSame('TX9997888', (string) $request->ptid);
52+
$this->assertSame('shop1', (string) $request->subId);
53+
$this->assertSame('14.65', (string) $request->amount);
54+
$this->assertSame('EUR', (string) $request->currency);
55+
$this->assertSame('client123', (string) $request->merchantClientId);
56+
$this->assertSame('EMAIL', (string) $request->customerIdType);
57+
$this->assertSame('[email protected]', (string) $request->customerId);
58+
$this->assertSame('true', (string) $request->validationOnly);
59+
$this->assertSame('+02:00', (string) $request->utcOffset);
60+
$this->assertSame('John', (string) $request->customerDetailsBasic->firstName);
61+
$this->assertSame('Doe', (string) $request->customerDetailsBasic->lastName);
62+
$this->assertSame('1976-12-30', (string) $request->customerDetailsBasic->dateOfBirth);
63+
}
64+
65+
public function testSendData()
66+
{
67+
$data = $this->request->getData();
68+
$response = $this->request->sendData($data);
69+
$this->assertSame('Omnipay\Paysafecard\Message\ValidatePayoutResponse', get_class($response));
70+
}
71+
72+
}

0 commit comments

Comments
 (0)