Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 71 additions & 55 deletions CustomerProfiles/create-customer-payment-profile.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,84 @@
<?php
require 'vendor/autoload.php';

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE", "phplog");

function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber){
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
$refId = 'ref' . time();
function createCustomerPaymentProfile($existingcustomerprofileid, $phoneNumber)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

// Set the transaction's refId
$refId = 'ref' . time();

// Create a Customer Profile Request
// 1. (Optionally) create a Payment Profile
// 2. (Optionally) create a Shipping Profile
// 3. Create a Customer Profile (or specify an existing profile)
// 4. Submit a CreateCustomerProfile Request
// 5. Validate Profile ID returned

// Set credit card information for payment profile
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4242424242424242");
$creditCard->setExpirationDate("2038-12");
$creditCard->setCardCode("142");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);

// Create the Bill To info for new payment type
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen".$phoneNumber);
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
$billto->setPhoneNumber($phoneNumber);
$billto->setfaxNumber("999-999-9999");

// Create a new Customer Payment Profile object
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofile->setDefaultPaymentProfile(true);

$paymentprofiles[] = $paymentprofile;

// Assemble the complete transaction request
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);

$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber( "4242424242424242");
$creditCard->setExpirationDate( "2038-12");
$creditCard->setCardCode( "142");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
// Add an existing profile id to the request
$paymentprofilerequest->setCustomerProfileId($existingcustomerprofileid);
$paymentprofilerequest->setPaymentProfile($paymentprofile);
$paymentprofilerequest->setValidationMode("liveMode");

// Create the Bill To info for new payment type
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Mrs Mary".$phoneNumber);
$billto->setLastName("Doe");
$billto->setCompany("My company");
$billto->setAddress("123 Main St.");
$billto->setCity("Bellevue");
$billto->setState("WA");
$billto->setZip("98004");
$billto->setPhoneNumber($phoneNumber);
$billto->setfaxNumber("999-999-9999");
$billto->setCountry("USA");
// Create the controller and get the response
$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

// Create a new Customer Payment Profile
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofile->setDefaultPaymentProfile(true);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
} else {
echo "Create Customer Payment Profile: ERROR Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";

$paymentprofiles[] = $paymentprofile;
}
return $response;
}

// Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);
//Use an existing profile id
$paymentprofilerequest->setCustomerProfileId( $existingcustomerprofileid );
$paymentprofilerequest->setPaymentProfile( $paymentprofile );
$paymentprofilerequest->setValidationMode("liveMode");
$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
}
else
{
echo "Create Customer Payment Profile: ERROR Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";

}
return $response;
}
if(!defined('DONT_RUN_SAMPLES'))
createCustomerPaymentProfile("1807545561","000-000-0009");
if (!defined('DONT_RUN_SAMPLES')) {
createCustomerPaymentProfile("1807545561", "000-000-0009");
}
?>
73 changes: 39 additions & 34 deletions CustomerProfiles/create-customer-profile-from-transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,49 @@

define("AUTHORIZENET_LOG_FILE", "phplog");

function createCustomerProfileFromTransaction($transId= "2249066517")
{
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
function createCustomerProfileFromTransaction($transId= "2249066517")
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

// Set the transaction's refId
$refId = 'ref' . time();

$customerProfile = new AnetAPI\CustomerProfileBaseType();
$customerProfile->setMerchantCustomerId("123212");
$customerProfile->setEmail(rand(0,10000) . "@test" .".com");
$customerProfile->setDescription(rand(0,10000) ."sample description");
$customerProfile = new AnetAPI\CustomerProfileBaseType();
$customerProfile->setMerchantCustomerId("123212");
$customerProfile->setEmail(rand(0, 10000) . "@test" .".com");
$customerProfile->setDescription(rand(0, 10000) ."sample description");

$request = new AnetAPI\CreateCustomerProfileFromTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransId($transId);
// You can either specify the customer information in form of customerProfileBaseType object
$request->setCustomer($customerProfile);
// OR
// You can just provide the customer Profile ID
//$request->setCustomerProfileId("123343");
$request = new AnetAPI\CreateCustomerProfileFromTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransId($transId);

$controller = new AnetController\CreateCustomerProfileFromTransactionController($request);
// You can either specify the customer information in form of customerProfileBaseType object
$request->setCustomer($customerProfile);
// OR
// You can just provide the customer Profile ID
//$request->setCustomerProfileId("123343");

$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
$controller = new AnetController\CreateCustomerProfileFromTransactionController($request);

if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
}
else
{
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
//provide a transaction that has customer information
if(!defined('DONT_RUN_SAMPLES'))
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
echo "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
} else {
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}

// Provide a transaction that has customer information
if (!defined('DONT_RUN_SAMPLES')) {
createCustomerProfileFromTransaction("2249066517");
}

?>
137 changes: 76 additions & 61 deletions CustomerProfiles/create-customer-profile-with-accept-nonce.php
Original file line number Diff line number Diff line change
@@ -1,75 +1,90 @@
<?php
require 'vendor/autoload.php';

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE", "phplog");

function createCustomerProfileWithAcceptNonce($email){

// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
$refId = 'ref' . time();
function createCustomerProfileWithAcceptNonce($email)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

// Set the transaction's refId
$refId = 'ref' . time();

// Create a Customer Profile Request
// 1. (Optionally) create a Payment Profile
// 2. (Optionally) create a Shipping Profile
// 3. Create a Customer Profile (or specify an existing profile)
// 4. Submit a CreateCustomerProfile Request
// 5. Validate Profile ID returned

// Set the payment data for the payment profile to a token obtained from Accept.js
$op = new AnetAPI\OpaqueDataType();
$op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
$op->setDataValue("119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setOpaqueData($op);


// Create the Bill To info for new payment type
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
$billto->setPhoneNumber($phoneNumber);
$billto->setfaxNumber("999-999-9999");

// Create a new Customer Payment Profile object
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentOne);
$paymentprofile->setDefaultPaymentProfile(true);

$paymentprofiles[] = $paymentprofile;

// Create the payment data for an accept token
$op = new AnetAPI\OpaqueDataType();
$op->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
$op->setDataValue("9475089993864215505001");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setOpaqueData($op);
// Create a new CustomerProfileType and add the payment profile object
$customerprofile = new AnetAPI\CustomerProfileType();
$customerprofile->setDescription("Customer Test PHP Accept Test");

// Create the Bill To info
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");

// Create a Customer Profile Request
// 1. create a Payment Profile
// 2. create a Customer Profile
// 3. Submit a CreateCustomerProfile Request
// 4. Validate Profiiel ID returned
$customerprofile->setMerchantCustomerId("M_".$email);
$customerprofile->setEmail($email);
$customerprofile->setPaymentProfiles($paymentprofiles);

$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
// Assemble the complete transaction request
$request = new AnetAPI\CreateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setProfile($customerprofile);

$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentOne);
$paymentprofiles[] = $paymentprofile;
$customerprofile = new AnetAPI\CustomerProfileType();
$customerprofile->setDescription("Customer Test PHP Accept Test");
// Create the controller and get the response
$controller = new AnetController\CreateCustomerProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

$customerprofile->setMerchantCustomerId("M_".$email);
$customerprofile->setEmail($email);
$customerprofile->setPaymentProfiles($paymentprofiles);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
echo "Succesfully created customer profile : " . $response->getCustomerProfileId() . "\n";
$paymentProfiles = $response->getCustomerPaymentProfileIdList();
echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n";
} else {
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}

$request = new AnetAPI\CreateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);
$request->setProfile($customerprofile);
$controller = new AnetController\CreateCustomerProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "Succesfully create customer profile : " . $response->getCustomerProfileId() . "\n";
$paymentProfiles = $response->getCustomerPaymentProfileIdList();
echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n";
}
else
{
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
if(!defined('DONT_RUN_SAMPLES'))
createCustomerProfileWithAcceptNonce("test123@test.com");
if (!defined('DONT_RUN_SAMPLES')) {
createCustomerProfileWithAcceptNonce("test123@test.com");
}
?>
Loading