This repository was archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuthorizeNetARB.php
More file actions
136 lines (120 loc) · 3.55 KB
/
AuthorizeNetARB.php
File metadata and controls
136 lines (120 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Problematic\AuthNetBundle\AuthorizeNet\API\ARB;
use Problematic\AuthNetBundle\AuthorizeNet\Shared\AuthorizeNetRequest;
/**
* Easily interact with the Authorize.Net ARB XML API.
*
* @package AuthorizeNet
* @subpackage AuthorizeNetARB
* @link http://www.authorize.net/support/ARB_guide.pdf ARB Guide
*/
/**
* A class to send a request to the ARB XML API.
*
* @package AuthorizeNet
* @subpackage AuthorizeNetARB
*/
class AuthorizeNetARB extends AuthorizeNetRequest
{
const LIVE_URL = "https://api.authorize.net/xml/v1/request.api";
const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api";
private $_request_type;
private $_request_payload;
/**
* Optional. Used if the merchant wants to set a reference ID.
*
* @param string $refId
*/
public function setRefId($refId)
{
$this->_request_payload = ($refId ? "<refId>$refId</refId>" : "");
}
/**
* Create an ARB subscription
*
* @param AuthorizeNet_Subscription $subscription
*
* @return AuthorizeNetARB_Response
*/
public function createSubscription(AuthorizeNetSubscription $subscription)
{
$this->_request_type = "CreateSubscriptionRequest";
$this->_request_payload .= $subscription->getXml();
return $this->_sendRequest();
}
/**
* Update an ARB subscription
*
* @param int $subscriptionId
* @param AuthorizeNet_Subscription $subscription
*
* @return AuthorizeNetARB_Response
*/
public function updateSubscription($subscriptionId, AuthorizeNetSubscription $subscription)
{
$this->_request_type = "UpdateSubscriptionRequest";
$this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>";
$this->_request_payload .= $subscription->getXml();
return $this->_sendRequest();
}
/**
* Get status of a subscription
*
* @param int $subscriptionId
*
* @return AuthorizeNetARB_Response
*/
public function getSubscriptionStatus($subscriptionId)
{
$this->_request_type = "GetSubscriptionStatusRequest";
$this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>";
return $this->_sendRequest();
}
/**
* Cancel a subscription
*
* @param int $subscriptionId
*
* @return AuthorizeNetARB_Response
*/
public function cancelSubscription($subscriptionId)
{
$this->_request_type = "CancelSubscriptionRequest";
$this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>";
return $this->_sendRequest();
}
/**
*
*
* @param string $response
*
* @return AuthorizeNetARB_Response
*/
protected function _handleResponse($response)
{
return new AuthorizeNetARBResponse($response);
}
/**
* @return string
*/
protected function _getPostUrl()
{
return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL);
}
/**
* Prepare the XML document for posting.
*/
protected function _setPostString()
{
$this->_post_string =<<<XML
<?xml version="1.0" encoding="utf-8"?>
<ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>{$this->_api_login}</name>
<transactionKey>{$this->_transaction_key}</transactionKey>
</merchantAuthentication>
{$this->_request_payload}
</ARB{$this->_request_type}>
XML;
}
}