Skip to content

Commit

Permalink
Issue #7 partial
Browse files Browse the repository at this point in the history
Check PayPal pending flag and set isPending() appropriaely.
  • Loading branch information
judgej committed Dec 3, 2018
1 parent d1a0790 commit 7654e30
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/Interfaces/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,32 @@ interface Constants
*/
const CUSTOMER_TYPE_PERSON = 'P';
const CUSTOMER_TYPE_COMPANY = 'C';

/**
* Response codes.
* These are listed in some parts of the documentation as
* strings with leading zeros, and in other parts as integers.
* So there is some ambiguity about what we will receive, and
* whether we can guarantee it can be cast to an integer for
* comparison.
* CHECKME: what is AUTHENTIFIED?
*/
const RESPONSE_CODE_INCOMPLETE = '00';
const RESPONSE_CODE_READY_FOR_SETTLEMENT = '01';
const RESPONSE_CODE_DEBIT_WAITING_SETTLEMENT = '02';
const RESPONSE_CODE_CREDIT_WAITING_SETTLEMENT = '03';
const RESPONSE_CODE_DECLINED = '04';
const RESPONSE_CODE_REFERRAL_STATUS = '05';
const RESPONSE_CODE_CANCELLED_MERCHANT_1 = '06';
const RESPONSE_CODE_CANCELLED_MERCHANT_2 = '07';
const RESPONSE_CODE_CANCELLED_MERCHANT_3 = '08';
const RESPONSE_CODE_CANCELLED_USER = '09';
const RESPONSE_CODE_AUTHENTIFIED = '11';
const RESPONSE_CODE_AUTHENTIFIED_AUTHORIZED = '12';
const RESPONSE_CODE_PENDING_TRANSACTION = '13';
const RESPONSE_CODE_TIMEOUT = '14';
const RESPONSE_CODE_CARD_CHECK_PROCESSED = '15';
const RESPONSE_CODE_RECORD_NOT_FOUND = '20';
const RESPONSE_CODE_ALREADY_SETTLED = '21';
const RESPONSE_CODE_MULTIPLE_ONE_TRANSACTION = '30';
}
14 changes: 12 additions & 2 deletions src/Traits/HasCompleteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function isSuccessful()
{
$status = $this->getStatus();

return $status === Gateway::STATUS_SUCCESS || $status === Gateway::STATUS_ACCEPTED;
return $status === Gateway::STATUS_SUCCESS
|| $status === Gateway::STATUS_ACCEPTED;
}

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

/**
* @return bool
*/
public function isPending()
{
return $this->getPendingPayPal() !== null;
}

/**
* CHECKME: is the virtualCardno the same thing, but for specific payment methods?
*
Expand Down Expand Up @@ -204,7 +213,8 @@ public function getAmountMinorUnits()

/**
* Authorization response code. See docs for details.
* @return string '01' or '02'
* @return string '01' or '02' for successful transaction.
* Other codes for unsuccessful transactions (such as 13 for pending).
*/
public function getResponseCode()
{
Expand Down
62 changes: 62 additions & 0 deletions tests/Message/CompleteResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,61 @@ public function setUp()
"uppMsgType" => "web",
]
);

$this->responsePendingPayPal = new CompleteResponse(
$this->getMockRequest(),
[
"uppCustomerEmail"=> "[email protected]",
"testOnly"=> "yes",
"amount"=> "2250",
"pmethod"=> "PAP",
"itemamt"=> "2250",
"uppWebResponseMethod"=> "POST",
"sign2"=> "d878c372972f03c8947af261ea9522e99ac5bb48c1a079cb4a84ec16a987fa4d",
"uppCustomerName"=> "Jason Judge",
"sign"=> "7b59c12fa3dd680771b2cd8cdc4eb394cf12f2f4a39a8e8d7e5dde0e295670b7",
"uppCustomerCountry"=> "DEU",
"uppCustomerCity"=> "Freiburg",
"taxamt1"=> "0",
"uppCustomerZipCode"=> "79111",
"taxamt0"=> "0",
"payPalAllowNote"=> "1",
"refno"=> "382583328377",
"uppReturnMaskedCc"=> "yes",
"uppCustomerDetails"=> "return",
"language"=> "en",
"uppDisplayShippingDetails"=> "yes",
"reqtype"=> "CAA",
"acqAuthorizationCode"=> "8Y894304WN001691G",
"uppCustomerStreet"=> "ESpachstr. 1",
"taxamt"=> "0",
"name1"=> "Item2",
"theme"=> "DT2015",
"name0"=> "Item1",
"number1"=> "2",
"number0"=> "1",
"pendingPayPal"=> "yes",
"responseMessage"=> "PayPal transaction successful/pending",
"uppTransactionId"=> "181203004654632546",
"uppForwardCustomerDetails"=> "yes",
"responseCode"=> "01",
"merchantId"=> "1100016183",
"redirectMethod"=> "GET",
"currency"=> "GBP",
"amt1"=> "250",
"amt0"=> "1000",
"version"=> "1.0.2",
"authorizationCode"=> "719912597",
"shippingamt"=> "0",
"qty1"=> "1",
"desc1"=> "This is Item Two",
"uppTermsLink"=> "https://academe.co.uk/",
"qty0"=> "2",
"desc0"=> "This is Item One",
"status" => "success",
"uppMsgType"=> "web",
]
);
}

public function testSuccess()
Expand All @@ -89,4 +144,11 @@ public function testCancelled()
$this->assertFalse($this->responseCancel->isSuccessful());
$this->assertTrue($this->responseCancel->isCancelled());
}

public function testPendingPayal()
{
$this->assertTrue($this->responsePendingPayPal->isSuccessful());
$this->assertFalse($this->responsePendingPayPal->isCancelled());
$this->assertTrue($this->responsePendingPayPal->isPending());
}
}

0 comments on commit 7654e30

Please sign in to comment.