Skip to content

Commit 8dc6c53

Browse files
authored
Merge pull request AuthorizeNet#75 from adavidw/master
Add CustomerData examples; fix formatting issues; fix TravisCI. Thanks!
2 parents 84e877e + 58fbffb commit 8dc6c53

File tree

8 files changed

+77
-60
lines changed

8 files changed

+77
-60
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@
4343
# PHP Storm
4444
/.idea/*
4545

46+
# Operating system files
47+
.DS_Store

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ php:
44
- 5.5
55
- 5.6
66
- 7.0
7+
- 7.1
78

89
sudo: false
910

1011
before_script:
11-
- composer install --prefer-dist --ignore-platform-reqs
12+
- composer install --prefer-dist
1213

1314
script:
1415
- phpunit test-runner.php .

PaymentTransactions/authorize-credit-card.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ function authorizeCreditCard($amount){
3535
$customerAddress->setZip("44628");
3636
$customerAddress->setCountry("USA");
3737

38+
// Set the customer's identifying information
39+
$CustomerData = new AnetAPI\CustomerDataType();
40+
$CustomerData->setType("individual");
41+
$CustomerData->setId("99999456654");
42+
$CustomerData->setEmail("[email protected]");
43+
3844
// Create a TransactionRequestType object
3945
$transactionRequestType = new AnetAPI\TransactionRequestType();
4046
$transactionRequestType->setTransactionType( "authOnlyTransaction");
4147
$transactionRequestType->setAmount($amount);
4248
$transactionRequestType->setOrder($order);
4349
$transactionRequestType->setPayment($paymentOne);
4450
$transactionRequestType->setBillTo($customerAddress);
51+
$transactionRequestType->setCustomer($CustomerData);
4552

4653
$request = new AnetAPI\CreateTransactionRequest();
4754
$request->setMerchantAuthentication($merchantAuthentication);
@@ -60,9 +67,9 @@ function authorizeCreditCard($amount){
6067

6168
if ($tresponse != null && $tresponse->getMessages() != null)
6269
{
63-
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
64-
echo " Successfully created a transaction with Auth code : " . $tresponse->getAuthCode() . "\n";
65-
echo " TRANS ID : " . $tresponse->getTransId() . "\n";
70+
echo " Transaction Response Code : " . $tresponse->getResponseCode() . "\n";
71+
echo " Successfully created an authOnly transaction with Auth Code : " . $tresponse->getAuthCode() . "\n";
72+
echo " Transaction ID : " . $tresponse->getTransId() . "\n";
6673
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
6774
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
6875
}

PaymentTransactions/charge-credit-card.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ function chargeCreditCard($amount){
3535
$customerAddress->setZip("44628");
3636
$customerAddress->setCountry("USA");
3737

38+
// Set the customer's identifying information
39+
$CustomerData = new AnetAPI\CustomerDataType();
40+
$CustomerData->setType("individual");
41+
$CustomerData->setId("99999456654");
42+
$CustomerData->setEmail("[email protected]");
43+
3844
// Create a TransactionRequestType object
3945
$transactionRequestType = new AnetAPI\TransactionRequestType();
4046
$transactionRequestType->setTransactionType( "authCaptureTransaction");
4147
$transactionRequestType->setAmount($amount);
4248
$transactionRequestType->setOrder($order);
4349
$transactionRequestType->setPayment($paymentOne);
4450
$transactionRequestType->setBillTo($customerAddress);
51+
$transactionRequestType->setCustomer($CustomerData);
4552

4653
$request = new AnetAPI\CreateTransactionRequest();
4754
$request->setMerchantAuthentication($merchantAuthentication);
@@ -60,9 +67,9 @@ function chargeCreditCard($amount){
6067

6168
if ($tresponse != null && $tresponse->getMessages() != null)
6269
{
63-
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
64-
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
65-
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
70+
echo " Transaction Response Code : " . $tresponse->getResponseCode() . "\n";
71+
echo " Successfully created an authCapture transaction with Auth Code : " . $tresponse->getAuthCode() . "\n";
72+
echo " Transaction ID : " . $tresponse->getTransId() . "\n";
6673
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
6774
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
6875
}

PaymentTransactions/get-an-accept-payment-page.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,54 @@
77

88
function getAnAcceptPaymentPage()
99
{
10-
// Common setup for API credentials
11-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
12-
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
13-
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
10+
// Common setup for API credentials
11+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
12+
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
13+
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
1414

15-
//create a transaction
16-
$transactionRequestType = new AnetAPI\TransactionRequestType();
17-
$transactionRequestType->setTransactionType( "authCaptureTransaction");
18-
$transactionRequestType->setAmount("12.23");
15+
//create a transaction
16+
$transactionRequestType = new AnetAPI\TransactionRequestType();
17+
$transactionRequestType->setTransactionType("authCaptureTransaction");
18+
$transactionRequestType->setAmount("12.23");
1919

20-
// Set Hosted Form options
21-
$setting1 = new AnetAPI\SettingType();
22-
$setting1->setSettingName("hostedPaymentButtonOptions");
23-
$setting1->setSettingValue("{\"text\": \"Pay\"}");
20+
// Set Hosted Form options
21+
$setting1 = new AnetAPI\SettingType();
22+
$setting1->setSettingName("hostedPaymentButtonOptions");
23+
$setting1->setSettingValue("{\"text\": \"Pay\"}");
2424

25-
$setting2 = new AnetAPI\SettingType();
26-
$setting2->setSettingName("hostedPaymentOrderOptions");
27-
$setting2->setSettingValue("{\"show\": false}");
25+
$setting2 = new AnetAPI\SettingType();
26+
$setting2->setSettingName("hostedPaymentOrderOptions");
27+
$setting2->setSettingValue("{\"show\": false}");
2828

29-
$setting3 = new AnetAPI\SettingType();
30-
$setting3->setSettingName("hostedPaymentReturnOptions");
31-
$setting3->setSettingValue("{\"url\": \"https://mysite.com/receipt\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}");
29+
$setting3 = new AnetAPI\SettingType();
30+
$setting3->setSettingName("hostedPaymentReturnOptions");
31+
$setting3->setSettingValue("{\"url\": \"https://mysite.com/receipt\", \"cancelUrl\": \"https://mysite.com/cancel\", \"showReceipt\": true}");
3232

33-
// Build transaction request
34-
$request = new AnetAPI\GetHostedPaymentPageRequest();
35-
$request->setMerchantAuthentication($merchantAuthentication);
36-
$request->setTransactionRequest($transactionRequestType);
33+
// Build transaction request
34+
$request = new AnetAPI\GetHostedPaymentPageRequest();
35+
$request->setMerchantAuthentication($merchantAuthentication);
36+
$request->setTransactionRequest($transactionRequestType);
3737

38-
$request->addToHostedPaymentSettings($setting1);
39-
$request->addToHostedPaymentSettings($setting2);
40-
$request->addToHostedPaymentSettings($setting3);
41-
42-
//execute request
43-
$controller = new AnetController\GetHostedPaymentPageController($request);
44-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
45-
46-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
47-
{
48-
echo $response->getToken()."\n";
49-
}
50-
else
51-
{
52-
echo "ERROR : Failed to get hosted payment page token\n";
53-
$errorMessages = $response->getMessages()->getMessage();
54-
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
55-
}
56-
return $response;
38+
$request->addToHostedPaymentSettings($setting1);
39+
$request->addToHostedPaymentSettings($setting2);
40+
$request->addToHostedPaymentSettings($setting3);
41+
42+
//execute request
43+
$controller = new AnetController\GetHostedPaymentPageController($request);
44+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
45+
46+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
47+
{
48+
echo $response->getToken()."\n";
49+
}
50+
else
51+
{
52+
echo "ERROR : Failed to get hosted payment page token\n";
53+
$errorMessages = $response->getMessages()->getMessage();
54+
echo "RESPONSE : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
55+
}
56+
return $response;
5757
}
5858
if(!defined('DONT_RUN_SAMPLES'))
59-
getAnAcceptPaymentPage();
59+
getAnAcceptPaymentPage();
6060
?>

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ This repository contains working code samples which demonstrate PHP integration
66
The samples are organized just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference
77

88

9-
##Using the Sample Code
9+
## Using the Sample Code
1010

1111
The samples are all completely independent and self-contained so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line.
1212

13-
##Running the Samples
13+
## Running the Samples
1414
Clone this repository.
1515
Run "composer update" in the root directory.
1616
Run the individual samples e.g.
17-
````
17+
```
1818
php PaymentTransactions/charge-credit-card.php
19-
````
19+
```
2020
Note: If during "composer update", you get the error "composer failed to open stream invalid argument", go to your php.ini file (present where you have installed PHP), and uncomment the following lines:
21-
````
21+
```
2222
extension=php_openssl.dll
2323
extension=php_curl.dll
24-
````
24+
```
2525
On Windows systems, you also have to uncomment:
26-
````
26+
```
2727
extension_dir = "ext"
28-
````
28+
```
2929
Then run the composer update again. You might have to restart your machine before the changes take effect.
3030

31-
##What if I'm not using Composer?
31+
## What if I'm not using Composer?
3232
We provide a custom `SPL` autoloader, just [download the SDK.](https://github.com/AuthorizeNet/sdk-php/releases):
3333

3434
```php

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"require": {
33
"php": ">=5.5",
44
"ext-curl": "*",
5-
"phpunit/phpunit": "~4.0",
5+
"phpunit/phpunit": "~4.8||~6.0",
66
"authorizenet/authorizenet": "1.9.2"
77
},
88
"autoload": {

test-runner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232

3333
error_reporting($errorlevel);
34-
class TestRunner extends PHPUnit_Framework_TestCase
34+
class TestRunner extends PHPUnit\Framework\TestCase
3535
{
3636
public static $apiLoginId = "5KP3u95bQpv";
3737
public static $transactionKey = "346HZ32z3fP4hTG2";

0 commit comments

Comments
 (0)