Skip to content

Commit b66ea0d

Browse files
committed
Add opaqueData to createCard on CIM
1 parent b8bb904 commit b66ea0d

File tree

2 files changed

+70
-11
lines changed

2 files changed

+70
-11
lines changed

src/Message/CIMAbstractRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,44 @@ public function getCustomerPaymentProfileId()
7272
return $this->getParameter('customerPaymentProfileId');
7373
}
7474

75+
/**
76+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
77+
* @return string
78+
*/
79+
public function getOpaqueDataDescriptor()
80+
{
81+
return $this->getParameter('opaqueDataDescriptor');
82+
}
83+
84+
/**
85+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
86+
* @return string
87+
*/
88+
public function getOpaqueDataValue()
89+
{
90+
return $this->getParameter('opaqueDataValue');
91+
}
92+
93+
/**
94+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
95+
* @param string
96+
* @return string
97+
*/
98+
public function setOpaqueDataDescriptor($value)
99+
{
100+
return $this->setParameter('opaqueDataDescriptor', $value);
101+
}
102+
103+
/**
104+
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
105+
* @param string
106+
* @return string
107+
*/
108+
public function setOpaqueDataValue($value)
109+
{
110+
return $this->setParameter('opaqueDataValue', $value);
111+
}
112+
75113
/**
76114
* Flag to force update consumer payment profile if duplicate is found
77115
*

src/Message/CIMCreateCardRequest.php

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@ class CIMCreateCardRequest extends CIMAbstractRequest
1313

1414
public function getData()
1515
{
16-
$this->validate('card');
17-
18-
/** @var CreditCard $card */
19-
$card = $this->getCard();
20-
$card->validate();
2116

2217
$data = $this->getBaseData();
18+
$this->validateCard($data);
2319
$this->addProfileData($data);
2420
$this->addTransactionSettings($data);
2521

2622
return $data;
2723
}
2824

25+
/**
26+
* Validate card or skip if opaque data is available
27+
*
28+
* @param \SimpleXMLElement $data
29+
*/
30+
protected function validateCard(\SimpleXMLElement $data){
31+
32+
if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) {
33+
return;
34+
}
35+
36+
$this->validate('card');
37+
38+
/** @var CreditCard $card */
39+
$card = $this->getCard();
40+
$card->validate();
41+
42+
}
43+
2944
/**
3045
* Add customer profile data to the specified xml element
3146
*
@@ -97,12 +112,18 @@ protected function addBillingData(\SimpleXMLElement $data)
97112
}
98113

99114
$req = $data->addChild('payment');
100-
$req->creditCard->cardNumber = $card->getNumber();
101-
$req->creditCard->expirationDate = $card->getExpiryDate('Y-m');
102-
if ($card->getCvv()) {
103-
$req->creditCard->cardCode = $card->getCvv();
104-
} else {
105-
$this->setValidationMode(self::VALIDATION_MODE_NONE);
115+
if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) {
116+
//Use opaqueData if available instead of card data
117+
$req->opaqueData->dataDescriptor = $this->getOpaqueDataDescriptor();
118+
$req->opaqueData->dataValue = $this->getOpaqueDataValue();
119+
}else{
120+
$req->creditCard->cardNumber = $card->getNumber();
121+
$req->creditCard->expirationDate = $card->getExpiryDate('Y-m');
122+
if ($card->getCvv()) {
123+
$req->creditCard->cardCode = $card->getCvv();
124+
} else {
125+
$this->setValidationMode(self::VALIDATION_MODE_NONE);
126+
}
106127
}
107128
}
108129
}

0 commit comments

Comments
 (0)