Skip to content

Commit 1a699aa

Browse files
authored
Merge pull request #45 from alberto1el/alberto1el-feature-deleteCustomerPaymentProfile
feature delete customer payment profile
2 parents 6e1990f + 17d1a90 commit 1a699aa

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

src/CIMGateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public function createCard(array $parameters = array())
4646
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMCreateCardRequest', $parameters);
4747
}
4848

49+
public function getPaymentProfile(array $parameters = array())
50+
{
51+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMGetPaymentProfileRequest', $parameters);
52+
}
53+
54+
public function deleteCard(array $parameters = array())
55+
{
56+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMDeletePaymentProfileRequest', $parameters);
57+
}
58+
4959
public function authorize(array $parameters = array())
5060
{
5161
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMAuthorizeRequest', $parameters);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* Request to delete a customer payment profile for an existing customer and existing payment profile.
7+
*/
8+
class CIMDeletePaymentProfileRequest extends CIMAbstractRequest
9+
{
10+
protected $requestType = 'deleteCustomerPaymentProfileRequest';
11+
12+
public function getData()
13+
{
14+
$this->validate('customerProfileId', 'customerPaymentProfileId');
15+
16+
$data = $this->getBaseData();
17+
$data->customerProfileId = $this->getCustomerProfileId();
18+
$data->customerPaymentProfileId = $this->getCustomerPaymentProfileId();
19+
20+
return $data;
21+
}
22+
23+
public function sendData($data)
24+
{
25+
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
26+
$data = $data->saveXml();
27+
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
28+
29+
return $this->response = new CIMDeletePaymentProfileResponse($this, $httpResponse->getBody());
30+
}
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* Authorize.Net CIM Delete payment profile Response
7+
*/
8+
class CIMDeletePaymentProfileResponse extends CIMAbstractResponse
9+
{
10+
protected $responseType = 'deleteCustomerPaymentProfileResponse';
11+
}

tests/CIMGatewayIntegrationTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,41 @@ public function testCustomerAndPaymentProfile()
112112
);
113113
}
114114

115+
public function testPaymentProfileDelete()
116+
{
117+
118+
// Create a customer profile with the specified email (email is the identifier) (to have a deletable payment profile)
119+
$email = uniqid('', true) . '@example.com';
120+
$cardRef = $this->createCard(array('email' => $email));
121+
$cardRef = json_decode($cardRef,true);
122+
123+
//Delete the recently created payment profile (deletes the payment profile only, not the customer profile)
124+
$params = array(
125+
'customerProfileId' => $cardRef['customerProfileId'],
126+
'customerPaymentProfileId' => $cardRef['customerPaymentProfileId']
127+
);
128+
$defaults = array( );
129+
$params = array_merge($defaults, $params);
130+
$request = $this->gateway->deleteCard($params);
131+
$request->setDeveloperMode(true);
132+
/* @var $response CIMResponse */
133+
$response = $request->send();
134+
$this->assertTrue($response->isSuccessful(), 'Should be successful as we have deleted a payment profile');
135+
136+
/* retrieve the recently deleted payment profile for the customer profile from authorize.net (returns NULL) */
137+
$params = array(
138+
'customerProfileId' => $cardRef['customerProfileId'],
139+
'customerPaymentProfileId' => $cardRef['customerPaymentProfileId']
140+
);
141+
$defaults = array( );
142+
$params = array_merge($defaults, $params);
143+
$request = $this->gateway->getPaymentProfile($params);
144+
$request->setDeveloperMode(true);
145+
/* @var $response CIMResponse */
146+
$response = $request->send();
147+
$this->assertNull($response->getCustomerPaymentProfileId(), 'Should be null as we have deleted that payment profile');
148+
}
149+
115150
public function testAuthorizeCapture()
116151
{
117152
$cardRef = $this->createCard();

0 commit comments

Comments
 (0)