Skip to content

Commit 7654e30

Browse files
committed
Issue #7 partial
Check PayPal pending flag and set isPending() appropriaely.
1 parent d1a0790 commit 7654e30

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

src/Interfaces/Constants.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,32 @@ interface Constants
322322
*/
323323
const CUSTOMER_TYPE_PERSON = 'P';
324324
const CUSTOMER_TYPE_COMPANY = 'C';
325+
326+
/**
327+
* Response codes.
328+
* These are listed in some parts of the documentation as
329+
* strings with leading zeros, and in other parts as integers.
330+
* So there is some ambiguity about what we will receive, and
331+
* whether we can guarantee it can be cast to an integer for
332+
* comparison.
333+
* CHECKME: what is AUTHENTIFIED?
334+
*/
335+
const RESPONSE_CODE_INCOMPLETE = '00';
336+
const RESPONSE_CODE_READY_FOR_SETTLEMENT = '01';
337+
const RESPONSE_CODE_DEBIT_WAITING_SETTLEMENT = '02';
338+
const RESPONSE_CODE_CREDIT_WAITING_SETTLEMENT = '03';
339+
const RESPONSE_CODE_DECLINED = '04';
340+
const RESPONSE_CODE_REFERRAL_STATUS = '05';
341+
const RESPONSE_CODE_CANCELLED_MERCHANT_1 = '06';
342+
const RESPONSE_CODE_CANCELLED_MERCHANT_2 = '07';
343+
const RESPONSE_CODE_CANCELLED_MERCHANT_3 = '08';
344+
const RESPONSE_CODE_CANCELLED_USER = '09';
345+
const RESPONSE_CODE_AUTHENTIFIED = '11';
346+
const RESPONSE_CODE_AUTHENTIFIED_AUTHORIZED = '12';
347+
const RESPONSE_CODE_PENDING_TRANSACTION = '13';
348+
const RESPONSE_CODE_TIMEOUT = '14';
349+
const RESPONSE_CODE_CARD_CHECK_PROCESSED = '15';
350+
const RESPONSE_CODE_RECORD_NOT_FOUND = '20';
351+
const RESPONSE_CODE_ALREADY_SETTLED = '21';
352+
const RESPONSE_CODE_MULTIPLE_ONE_TRANSACTION = '30';
325353
}

src/Traits/HasCompleteResponse.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public function isSuccessful()
104104
{
105105
$status = $this->getStatus();
106106

107-
return $status === Gateway::STATUS_SUCCESS || $status === Gateway::STATUS_ACCEPTED;
107+
return $status === Gateway::STATUS_SUCCESS
108+
|| $status === Gateway::STATUS_ACCEPTED;
108109
}
109110

110111
/**
@@ -117,6 +118,14 @@ public function isCancelled()
117118
return $status === Gateway::STATUS_CANCEL;
118119
}
119120

121+
/**
122+
* @return bool
123+
*/
124+
public function isPending()
125+
{
126+
return $this->getPendingPayPal() !== null;
127+
}
128+
120129
/**
121130
* CHECKME: is the virtualCardno the same thing, but for specific payment methods?
122131
*
@@ -204,7 +213,8 @@ public function getAmountMinorUnits()
204213

205214
/**
206215
* Authorization response code. See docs for details.
207-
* @return string '01' or '02'
216+
* @return string '01' or '02' for successful transaction.
217+
* Other codes for unsuccessful transactions (such as 13 for pending).
208218
*/
209219
public function getResponseCode()
210220
{

tests/Message/CompleteResponseTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,61 @@ public function setUp()
6767
"uppMsgType" => "web",
6868
]
6969
);
70+
71+
$this->responsePendingPayPal = new CompleteResponse(
72+
$this->getMockRequest(),
73+
[
74+
"uppCustomerEmail"=> "jason.datatrans@academe.co.uk",
75+
"testOnly"=> "yes",
76+
"amount"=> "2250",
77+
"pmethod"=> "PAP",
78+
"itemamt"=> "2250",
79+
"uppWebResponseMethod"=> "POST",
80+
"sign2"=> "d878c372972f03c8947af261ea9522e99ac5bb48c1a079cb4a84ec16a987fa4d",
81+
"uppCustomerName"=> "Jason Judge",
82+
"sign"=> "7b59c12fa3dd680771b2cd8cdc4eb394cf12f2f4a39a8e8d7e5dde0e295670b7",
83+
"uppCustomerCountry"=> "DEU",
84+
"uppCustomerCity"=> "Freiburg",
85+
"taxamt1"=> "0",
86+
"uppCustomerZipCode"=> "79111",
87+
"taxamt0"=> "0",
88+
"payPalAllowNote"=> "1",
89+
"refno"=> "382583328377",
90+
"uppReturnMaskedCc"=> "yes",
91+
"uppCustomerDetails"=> "return",
92+
"language"=> "en",
93+
"uppDisplayShippingDetails"=> "yes",
94+
"reqtype"=> "CAA",
95+
"acqAuthorizationCode"=> "8Y894304WN001691G",
96+
"uppCustomerStreet"=> "ESpachstr. 1",
97+
"taxamt"=> "0",
98+
"name1"=> "Item2",
99+
"theme"=> "DT2015",
100+
"name0"=> "Item1",
101+
"number1"=> "2",
102+
"number0"=> "1",
103+
"pendingPayPal"=> "yes",
104+
"responseMessage"=> "PayPal transaction successful/pending",
105+
"uppTransactionId"=> "181203004654632546",
106+
"uppForwardCustomerDetails"=> "yes",
107+
"responseCode"=> "01",
108+
"merchantId"=> "1100016183",
109+
"redirectMethod"=> "GET",
110+
"currency"=> "GBP",
111+
"amt1"=> "250",
112+
"amt0"=> "1000",
113+
"version"=> "1.0.2",
114+
"authorizationCode"=> "719912597",
115+
"shippingamt"=> "0",
116+
"qty1"=> "1",
117+
"desc1"=> "This is Item Two",
118+
"uppTermsLink"=> "https://academe.co.uk/",
119+
"qty0"=> "2",
120+
"desc0"=> "This is Item One",
121+
"status" => "success",
122+
"uppMsgType"=> "web",
123+
]
124+
);
70125
}
71126

72127
public function testSuccess()
@@ -89,4 +144,11 @@ public function testCancelled()
89144
$this->assertFalse($this->responseCancel->isSuccessful());
90145
$this->assertTrue($this->responseCancel->isCancelled());
91146
}
147+
148+
public function testPendingPayal()
149+
{
150+
$this->assertTrue($this->responsePendingPayPal->isSuccessful());
151+
$this->assertFalse($this->responsePendingPayPal->isCancelled());
152+
$this->assertTrue($this->responsePendingPayPal->isPending());
153+
}
92154
}

0 commit comments

Comments
 (0)