CHECK IF A CUSTOMER HAS ENOUGH CREDIT AVAILABLE

Code

This code steps you through the process of validating a customer’s credit card information and authorizing a potential charge against the card.

You can test for both outcomes:
Approved: When you pass odd dollar amounts, payment authorizations are returned with an ‘Approved’ status.
Declined: When you pass even dollar amounts, payment authorizations are returned with a ‘Declined’ status.

The ‘Approved’ payment authorization does not charge the customer’s credit card.
For that Go to: Charge a Customer or Run a credit card transaction

The following sample code calls a routine from our Code Library.
Download pay2amigos.php
Or, download via GitHub

<?php
/***
* pay2amigos PHP Sample Code
*
# This code sample runs a $3.00 Credit Card Sale transaction
# against a customer using test payment information. If
# approved, a 2nd transaction is run to update the first transaction
# to $5.75, $2.75 more than the original $3.00.
# If using TEST mode, odd dollar amounts will return
# an approval and even dollar amounts will return a decline.
*/
include('../pay2amigos.php');
$accountID = "Merchant's Account ID Here";
$secretKey = "Merchant's Secret Key Here";
$mode = "TEST";
$payment = new pay2amigos(
   
$accountID,
   
$secretKey,
   
$mode
);
$payment->setCustomerInformation(array(
   
'firstName' => 'Bob',
   
'lastName' => 'Tester',
   
'addr1' => '1234 Test St.',
   
'addr2' => 'Apt #500',
   
'city' => 'Testville',
   
'state' => 'IL',
   
'zip' =>'54321',
   
'country' => 'USA',
   
'phone' => '1231231234',
   
'email' => '[email protected]'
));
$payment->setCCInformation(array(
   
'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
   
'cardExpire' => '1225', // Card Expire: 12/25
   
'cvv2' => '123' // Card CVV2: 123
));
$payment->sale('3.00');
$payment->process();
// If transaction was approved..
if ($payment->isSuccessfulResponse()) {
   
   
$paymentUpdate = new Pay2amigos(
       
$accountID,
       
$secretKey,
       
$mode
   
);
   
$paymentUpdate->update(
       
$payment->getTransID(),
       
'5.75' // add $2.75 to previous amount
   
);
   
// Makes the API Request to process update
   
$paymentUpdate->process();
   
// Reads the response from Pay2amigos
   
echo
   
'Transaction Status: '. $paymentUpdate->getStatus() . "\n" .
   
'Transaction Message: '. $paymentUpdate->getMessage() . "\n" .
   
'Transaction ID: '. $paymentUpdate->getTransID() . "\n" .
   
'AVS Response: ' . $paymentUpdate->getAVSResponse() . "\n" .
   
'CVS Response: ' . $paymentUpdate->getCVV2Response() . "\n" .
   
'Masked Account: ' . $paymentUpdate->getMaskedAccount() . "\n" .
   
'Card Type: ' . $paymentUpdate->getCardType() . "\n" .
   
'Authorization Code: ' . $paymentUpdate->getAuthCode() . "\n";
} else {
    echo
$payment->getMessage();
}
?>
Can’t find what you’re
looking for? We can help.

Contact 855*422-9385 for Integration Support.

compress_logo-cred-ms-gold-01a
logo-cred-komen-01a
footer-steve2018-award
cnp-2018-rev
footer-tsg2018-award
compress_pillar_2017