1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\FoxyStripe\Controller; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Dynamic\FoxyStripe\Model\FoxyCart; |
7
|
|
|
use SilverStripe\Control\Controller; |
8
|
|
|
use SilverStripe\Control\Director; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class DataTestController |
12
|
|
|
* @package Dynamic\FoxyStripe\Controller |
13
|
|
|
*/ |
14
|
|
|
class DataTestController extends Controller |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
19
|
|
|
*/ |
20
|
|
|
public function index() { |
21
|
|
|
|
22
|
|
|
$rules = Director::config()->get('rules'); |
23
|
|
|
$rule = array_search(FoxyStripeController::class, $rules); |
24
|
|
|
$myURL = Director::absoluteBaseURL() . explode('//', $rule)[0]; |
|
|
|
|
25
|
|
|
$myKey = FoxyCart::getStoreKey(); |
26
|
|
|
|
27
|
|
|
// TODO - make this external or changable |
28
|
|
|
$XMLOutput = <<<XML |
29
|
|
|
<?xml version='1.0' standalone='yes'?> |
30
|
|
|
<foxydata> |
31
|
|
|
<datafeed_version>XML FoxyCart Version 0.6</datafeed_version> |
32
|
|
|
<transactions> |
33
|
|
|
<transaction> |
34
|
|
|
<id>616</id> |
35
|
|
|
<store_id>9</store_id> |
36
|
|
|
<store_version>2.0</store_version> |
37
|
|
|
<is_test>1</is_test> |
38
|
|
|
<is_hidden>0</is_hidden> |
39
|
|
|
<data_is_fed>0</data_is_fed> |
40
|
|
|
<transaction_date>2010-08-19 13:50:00</transaction_date> |
41
|
|
|
<processor_response>Authorize.net Transaction ID:2154082729</processor_response> |
42
|
|
|
<transaction_date>2007-05-04 20:53:57</transaction_date> |
43
|
|
|
<customer_id>122</customer_id> |
44
|
|
|
<is_anonymous>0</is_anonymous> |
45
|
|
|
<minfraud_score>0</minfraud_score> |
46
|
|
|
<customer_first_name>John</customer_first_name> |
47
|
|
|
<customer_last_name>Doe</customer_last_name> |
48
|
|
|
<customer_company>Your Company</customer_company> |
49
|
|
|
<customer_address1>12345 Any Street</customer_address1> |
50
|
|
|
<customer_address2></customer_address2> |
51
|
|
|
<customer_city>Any City</customer_city> |
52
|
|
|
<customer_state>TN</customer_state> |
53
|
|
|
<customer_postal_code>37013</customer_postal_code> |
54
|
|
|
<customer_country>US</customer_country> |
55
|
|
|
<customer_phone>(123) 456-7890</customer_phone> |
56
|
|
|
<customer_email>[email protected]</customer_email> |
57
|
|
|
<customer_ip>71.228.237.177</customer_ip> |
58
|
|
|
<shipping_first_name>John</shipping_first_name> |
59
|
|
|
<shipping_last_name>Doe</shipping_last_name> |
60
|
|
|
<shipping_company></shipping_company> |
61
|
|
|
<shipping_address1>1234 Any Street</shipping_address1> |
62
|
|
|
<shipping_address2></shipping_address2> |
63
|
|
|
<shipping_city>Some City</shipping_city> |
64
|
|
|
<shipping_state>TN</shipping_state> |
65
|
|
|
<shipping_postal_code>37013</shipping_postal_code> |
66
|
|
|
<shipping_country>US</shipping_country> |
67
|
|
|
<shipping_phone></shipping_phone> |
68
|
|
|
<shipping_service_description>UPS: Ground</shipping_service_description> |
69
|
|
|
<purchase_order></purchase_order> |
70
|
|
|
<cc_number_masked>xxxxxxxxxxxx4242</cc_number_masked> |
71
|
|
|
<cc_type>Visa</cc_type> |
72
|
|
|
<cc_exp_month>08</cc_exp_month> |
73
|
|
|
<cc_exp_year>2013</cc_exp_year> |
74
|
|
|
<cc_start_date_month>06</cc_start_date_month> |
75
|
|
|
<cc_start_date_year>2008</cc_start_date_year> |
76
|
|
|
<cc_issue_number>01</cc_issue_number> |
77
|
|
|
<product_total>20.00</product_total> |
78
|
|
|
<tax_total>0.00</tax_total> |
79
|
|
|
<shipping_total>4.38</shipping_total> |
80
|
|
|
<order_total>24.38</order_total> |
81
|
|
|
<order_total>24.38</order_total> |
82
|
|
|
<payment_gateway_type>authorize</payment_gateway_type> |
83
|
|
|
<status>approved</status> |
84
|
|
|
<customer_password>1aab23051b24582c5dc8e23fc595d505</customer_password> |
85
|
|
|
<customer_password_salt>SSCtVKDnH1vAwuLyY2XHziIFv3fN5laN8DbYiIcUDBkZW2pP</customer_password_salt> |
86
|
|
|
<customer_password_hash_type>sha256_salted_suffix</customer_password_hash_type> |
87
|
|
|
<customer_password_hash_config>48</customer_password_hash_config> |
88
|
|
|
<custom_fields> |
89
|
|
|
<custom_field> |
90
|
|
|
<custom_field_name>My_Cool_Text</custom_field_name> |
91
|
|
|
<custom_field_value>Value123</custom_field_value> |
92
|
|
|
<custom_field_is_hidden>1</custom_field_is_hidden> |
93
|
|
|
</custom_field> |
94
|
|
|
<custom_field> |
95
|
|
|
<custom_field_name>Another_Custom_Field</custom_field_name> |
96
|
|
|
<custom_field_value>10</custom_field_value> |
97
|
|
|
<custom_field_is_hidden>1</custom_field_is_hidden> |
98
|
|
|
</custom_field> |
99
|
|
|
</custom_fields> |
100
|
|
|
<transaction_details> |
101
|
|
|
<transaction_detail> |
102
|
|
|
<product_name>foo</product_name> |
103
|
|
|
<product_price>20.00</product_price> |
104
|
|
|
<product_quantity>1</product_quantity> |
105
|
|
|
<product_weight>0.10</product_weight> |
106
|
|
|
<product_code></product_code> |
107
|
|
|
<parent_code></parent_code> |
108
|
|
|
<image></image> |
109
|
|
|
<url></url> |
110
|
|
|
<length></length> |
111
|
|
|
<width></width> |
112
|
|
|
<height></height> |
113
|
|
|
<expires></expires> |
114
|
|
|
<sub_token_url></sub_token_url> |
115
|
|
|
<subscription_nextdate>0000-00-00</subscription_nextdate> |
116
|
|
|
<subscription_enddate>0000-00-00</subscription_enddate> |
117
|
|
|
<is_future_line_item>0</is_future_line_item> |
118
|
|
|
<subscription_frequency>1m</subscription_frequency> |
119
|
|
|
<subscription_startdate>2007-07-07</subscription_startdate> |
120
|
|
|
<shipto>John Doe</shipto> |
121
|
|
|
<category_description>Default for all products</category_description> |
122
|
|
|
<category_code>DEFAULT</category_code> |
123
|
|
|
<product_delivery_type>shipped</product_delivery_type> |
124
|
|
|
<transaction_detail_options> |
125
|
|
|
<transaction_detail_option> |
126
|
|
|
<product_option_name>color</product_option_name> |
127
|
|
|
<product_option_value>blue</product_option_value> |
128
|
|
|
<price_mod></price_mod> |
129
|
|
|
<weight_mod></weight_mod> |
130
|
|
|
</transaction_detail_option> |
131
|
|
|
</transaction_detail_options> |
132
|
|
|
</transaction_detail> |
133
|
|
|
</transaction_details> |
134
|
|
|
<shipto_addresses> |
135
|
|
|
<shipto_address> |
136
|
|
|
<address_name>John Doe</address_name> |
137
|
|
|
<shipto_first_name>John</shipto_first_name> |
138
|
|
|
<shipto_last_name>Doe</shipto_last_name> |
139
|
|
|
<shipto_address1>2345 Some Address</shipto_address1> |
140
|
|
|
<shipto_address2></shipto_address2> |
141
|
|
|
<shipto_city>Some City</shipto_city> |
142
|
|
|
<shipto_state>TN</shipto_state> |
143
|
|
|
<shipto_postal_code>37013</shipto_postal_code> |
144
|
|
|
<shipto_country>US</shipto_country> |
145
|
|
|
<shipto_shipping_service_description>DHL: Next Afternoon</shipto_shipping_service_description> |
146
|
|
|
<shipto_subtotal>52.15</shipto_subtotal> |
147
|
|
|
<shipto_tax_total>6.31</shipto_tax_total> |
148
|
|
|
<shipto_shipping_total>15.76</shipto_shipping_total> |
149
|
|
|
<shipto_total>74.22</shipto_total> |
150
|
|
|
<shipto_custom_fields> |
151
|
|
|
<shipto_custom_field> |
152
|
|
|
<shipto_custom_field_name>My_Custom_Info</shipto_custom_field_name> |
153
|
|
|
<shipto_custom_field_value>john's stuff</shipto_custom_field_value> |
154
|
|
|
</shipto_custom_field> |
155
|
|
|
<shipto_custom_field> |
156
|
|
|
<shipto_custom_field_name>More_Custom_Info</shipto_custom_field_name> |
157
|
|
|
<shipto_custom_field_value>more of john's stuff</shipto_custom_field_value> |
158
|
|
|
</shipto_custom_field> |
159
|
|
|
</shipto_custom_fields> |
160
|
|
|
</shipto_address> |
161
|
|
|
</shipto_addresses> |
162
|
|
|
</transaction> |
163
|
|
|
</transactions> |
164
|
|
|
</foxydata> |
165
|
|
|
XML; |
166
|
|
|
|
167
|
|
|
$XMLOutput_encrypted = \rc4crypt::encrypt($myKey, $XMLOutput); |
|
|
|
|
168
|
|
|
$XMLOutput_encrypted = urlencode($XMLOutput_encrypted); |
169
|
|
|
|
170
|
|
|
$ch = curl_init(); |
171
|
|
|
curl_setopt($ch, CURLOPT_URL, $myURL); |
172
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, array("FoxyData" => $XMLOutput_encrypted)); |
173
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
174
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
175
|
|
|
|
176
|
|
|
$response = curl_exec($ch); |
177
|
|
|
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
178
|
|
|
curl_close($ch); |
179
|
|
|
|
180
|
|
|
if ($responseCode <= 400) { |
181
|
|
|
header("content-type:text/plain"); |
182
|
|
|
} |
183
|
|
|
print $response; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
} |
187
|
|
|
|