Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SecureToken for Authorization and Purchase #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 91 additions & 14 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
* echo "Transaction reference = " . $sale_id . "\n";
* }
* </code>
*
* ## Secure Token + Transparent Redirect Work Flow
*
* To avoid PCI compliance auditing on your server, you can use
* Payflow's secure token and transparent redirect. The work flow
* for authorization is similar to a sale with a divided data flow
* for the card and non-card data:
*
* @see https://developer.paypal.com/docs/classic/payflow/integration-guide/#pci-compliance-without-hosted-pages---transparent-redirect
*
*/
class AuthorizeRequest extends AbstractRequest
{
Expand Down Expand Up @@ -198,6 +208,56 @@ public function getPoNum()
return $this->getParameter('ponum');
}

public function getSecureTokenId()
{
return $this->getParameter('securetokenid');
}

public function setSecureTokenId($value)
{
return $this->setParameter('securetokenid', $value);
}

public function getCreateSecureToken()
{
return $this->getParameter('createsecuretoken');
}

public function setCreateSecureToken($value)
{
return $this->setParameter('createsecuretoken', $value);
}

public function getSilentTran()
{
return $this->getParameter('silenttran');
}

public function setSilentTran($value)
{
return $this->setParameter('silenttran', $value);
}

public function getReturnUrl()
{
return $this->getParameter('returnurl');
}

public function setReturnUrl($value)
{
return $this->setParameter('returnurl', $value);
}

public function getErrorUrl()
{
return $this->getParameter('errorurl');
}

public function setErrorUrl($value)
{
return $this->setParameter('errorurl', $value);
}

/**
* @deprecated
*/
Expand Down Expand Up @@ -237,25 +297,42 @@ public function getData()
$this->validate('amount');
$data = $this->getBaseData();

/* what if we're wanting a secure ref? */
if ($this->getCardReference()) {
$data['ORIGID'] = $this->getCardReference();
if ($this->getCard()) {
$data['CVV2'] = $this->getCard()->getCvv();
}
} else {
$this->validate('card');
$this->getCard()->validate();

$data['ACCT'] = $this->getCard()->getNumber();
$data['EXPDATE'] = $this->getCard()->getExpiryDate('my');
$data['CVV2'] = $this->getCard()->getCvv();
$data['BILLTOFIRSTNAME'] = $this->getCard()->getFirstName();
$data['BILLTOLASTNAME'] = $this->getCard()->getLastName();
$data['BILLTOSTREET'] = $this->getCard()->getAddress1();
$data['BILLTOCITY'] = $this->getCard()->getCity();
$data['BILLTOSTATE'] = $this->getCard()->getState();
$data['BILLTOZIP'] = $this->getCard()->getPostcode();
$data['BILLTOCOUNTRY'] = $this->getCard()->getCountry();
if ($this->getSecureTokenId() && !is_null($this->getCreateSecureToken())) {
$this->validate('securetokenid', 'createsecuretoken', 'silenttran', 'returnurl', 'errorurl');

$data['SECURETOKENID'] = $this->getSecureTokenId();
$data['CREATESECURETOKEN'] = $this->getCreateSecureToken() ? 'Y' : 'N';
$data['SILENTTRAN'] = $this->getSilentTran() ? 'TRUE' : 'FALSE';

if ($this->getReturnUrl()) {
$data['RETURNURL'] = $this->getReturnUrl();
}

if ($this->getErrorUrl()) {
$data['ERRORURL'] = $this->getErrorUrl();
}
} else {
$this->validate('card');
$this->getCard()->validate();

$data['ACCT'] = $this->getCard()->getNumber();
$data['EXPDATE'] = $this->getCard()->getExpiryDate('my');
$data['CVV2'] = $this->getCard()->getCvv();
$data['BILLTOFIRSTNAME'] = $this->getCard()->getFirstName();
$data['BILLTOLASTNAME'] = $this->getCard()->getLastName();
$data['BILLTOSTREET'] = $this->getCard()->getAddress1();
$data['BILLTOCITY'] = $this->getCard()->getCity();
$data['BILLTOSTATE'] = $this->getCard()->getState();
$data['BILLTOZIP'] = $this->getCard()->getPostcode();
$data['BILLTOCOUNTRY'] = $this->getCard()->getCountry();
}
}

$data['TENDER'] = 'C';
Expand Down Expand Up @@ -299,7 +376,7 @@ public function encodeData(array $data)
{
$output = array();
foreach ($data as $key => $value) {
$output[] = $key.'['.strlen($value).']='.$value;
$output[] = $key.'['.strlen((string) $value).']='.$value;
}

return implode('&', $output);
Expand Down