The mgiCreditCard Tag

Tag Behavior

The mgiCreditCard tag validates credit card numbers and authorizes credit cards for a specific amount via MacAuthorize. The mgiCreditCard tag requires access to a server running MacAuthorize.


Tag Syntax

The mgiCreditCard tag has one required parameters and no optional parameters for all functions. In addition, the mgiCreditCard tag has required parameters for each function. The tag form is:

<mgiCreditCard function="Function">

Required Parameters:

  • function="Function" where "Function" is the behavior of the mgiCreditCard tag. The "Validate" function validates the credit card number. The Validate function has one additional required parameter and returns one of two values when processed (see descriptions below). The "Authorize" function authorizes the credit card for the specified amount. The Authorize function has four additional required parameters and returns one of eight values when processed (see descriptions below).

Validate Function Required Parameter:

  • accountNumber="Number" where "Number" is the full credit card number to validate. Do not include spaces or other characters (e.g., dashes) in the credit card number.

Validate Function Values:

  • Yes - The validate function returns the value "Yes" if the credit card number is valid.
  • No - The validate function returns the value "No" if the credit card number is not valid.

Authorize Function Required Parameters:

  • merchantHandle="Handle" where "Handle" is a valid merchant account handle that is configured in MacAuthorize.
  • accountNumber="Number" where "Number" is the full credit card number to authorize. Do not include spaces or other characters (e.g., dashes) in the credit card number.
  • expirationDate="Date" where "Date" is the two-digit numeric month and two-digit numeric year that the credit card to authorize expires (e.g., 1201).
  • chargeAmount="Amount" where "Amount" is the two-decimal place total charge amount that will be authorized to the credit card (e.g., 19.95) Do not include other characters such as dollar signs in the value of the charge amount.
  • chargeDescription="Description" where "Description" is a short description of the charges to the credit card.

Authorize Function Optional Parameters:

  • taxAmount="Amount" where "Amount" is the two-decimal place tax amount on the purchase. Do not include other characters such as dollar signs in the value of the charge amount.

Authorize Function Values:

  • Pending - The authorize function returns the value "Pending" if the transaction is still pending and not yet submitted for authorization.
  • Authorized - The authorize function returns the value "Authorized" if the transaction has been approved.
  • Declined - The authorize function returns the value "Declined" if the transaction has been declined.
  • Referral - The authorize function returns the value "Referral" if the transaction requires a phone authorization or further instructions from the merchant bank.
  • Voided - The authorize function returns the value "Voided" if the transaction has been voided.
  • Pickup - The authorize function returns the value "Pickup" if the transaction has been declined and the merchant bank requests a hold on the card.
  • Error - The authorize function returns the value "Error" if an error occurred during the transaction.
  • Unknown - The authorize function returns the value "Unknown" if an unknown error has occurred.


Example Usage and Output

Validating and Authorizing via a Form Submission:

In this example, software orders are entered into a form and submitted.

On the "thank you" page, the credit card number is validated and the value of the credit card validation (Yes or No) is set in a page variable named "CCValidation":

<mgiSet name="CCValidation">
<mgiCreditCard function="Validate" accountNumber={mgiFieldContent name="CCNumber"}>
</mgiSet>

Below the credit card validation variable, an if statement determines the next action based on the credit card validation. If the "CCValidation" variable is "Yes" (the credit card is valid), then the credit card is authorized and the value of the credit card authorization is set in a page variable named "CCAuthorization". If the "CCValidation" variable is "No" (the credit card is not valid), then the message "The credit card number you entered is not valid. Please click the "Back" button on your browser and re-enter the card number." is displayed:

<mgiIf target="Variable" name="CCValidation" value="Yes">
<mgiSet name="CCAuthorization">
<mgiCreditCard function="Authorize" merchantHandle="SoftCompanyHandle" 
accountNumber={mgiFieldContent name="CCNumber"} expirationDate={mgiFieldContent name="Expire"}
chargeAmount={mgiFieldContent name="Total"} chargeDescription="Software Order">
</mgiSet>
<mgiElse>
The credit card number you entered is not valid.  Please click the "Back" button on 
your browser and re-enter the card number.
</mgiIf>

Below the credit card authorization, an if statement determines the next action based on the credit card authorization. If the credit card is authorized, then the product serial number is emailed to the customer and the message "Thank you for ordering our product. A serial number has been emailed to you. Please contact us if you have any questions." is displayed. If the credit card is not authorized for any reason, then the customer's information is emailed to the tech support department and the message "We have experienced an error while processing your order. A representative will contact you to resolve this issue as soon as possible." is displayed.

<mgiIf target="Variable" name="CCAuthorization" value="Authorized">
<mgiSendMail to={mgiFieldContent name="Email"} from="webmaster@domain.com"
Subject="Software Serial Number" mailserver="mail.domain.com">
Please save this message.  Your serial number is 1234-5678-9123Y.
</mgiSendMail> 
Thank you for ordering our product. A serial number has been emailed to
you.  Please contact us if you have any questions.
<mgiElse>
<mgiSendMail to="techsupport@domain.com" from="webmaster@domain.com" 
Subject="Order Error" mailserver="mail.domain.com">
The following order could not be authorized

Authorization Message: <mgiGet name="CCAuthorization">

   Name: <mgiFieldContent name="Name">
Address: <mgiFieldContent name="Address">
  Phone: <mgiFieldContent name="Phone">
  Email: <mgiFieldContent name="Email">
 
  Total: <mgiFieldContent name="Total">
  CCNum: <mgiFieldContent name="CCNumber">
  CCExp: <mgiFieldContent name="Expire">
</mgiSendMail>
We have experienced an error while processing your order.  A representative will
contact you to resolve this issue as soon as possible.
</mgiIf>

Validating and Authorizing via a Shopping Basket:

In this example, an order is placed using an MGI Shopping Basket.

On the confirm order page, the payment method is checked. If the payment method is credit card, the credit card number is validated and the value of the credit card validation (Yes or No) is set in a page variable named "CCValidation". Below the credit card validation variable, an if statement determines the next action based on the credit card validation. If the "CCValidation" variable is "Yes" (the credit card is valid), then the order confirmation is displayed via the mgiConfirmOrder tag. If the "CCValidation" variable is "No" (the credit card is not valid), then the message " The credit card number you entered is not valid. Please click the "Back" button on your browser and re-enter the card number." is displayed.

If the payment method is Check or Purchase Order, the order confirmation is displayed.

<mgiConditional id="1" lhs={mgiFieldContent name="shoppingBasketPaymentMethod"}
relationship="equals" rhs="creditCard">
<mgiSet name="CCValidation">
<mgiCreditCard function="Validate"
accountNumber={mgiFieldContent name="shoppingBasketCreditCardNumber"}>
</mgiSet>

<mgiConditional id="2" lhs={mgiGet name="CCValidation"} 
relationship="equals" rhs="Yes">

<FORM ACTION="orderprocessing.html" METHOD="Post">
<mgiConfirmOrder taxRate=".06" state="North Carolina">
Garden Supply Co.
1007 Main Ave
Raleigh NC 27606
</mgiConfirmOrder>
<mgiButton name="Send Order">
</FORM>

<mgiElse id="2">

The credit card number you entered is not valid.  
Please click the "Back" button on your browser and 
re-enter the card number.

</mgiConditional>
<mgiElse id="1">

<FORM ACTION="orderprocessing.html" METHOD="Post">
<mgiConfirmOrder taxRate=".06" state="North Carolina">
Garden Supply Co.
1007 Main Ave
Raleigh NC 27606
</mgiConfirmOrder>
<mgiButton name="Send Order">
</FORM>

</mgiConditional>

On the order processing page, determine the customer's payment method with a conditional comparison. If the customer is paying by credit card, authorize the credit card number. The authorize function of mgiCreditCard authorizes the credit card for the total order amount. Set the value of the credit card authorization in a variable, then perform a conditional comparison with the value of the variable to determine the action on the send order page.

The credit card number, expiration month, expiration year and order total values are automatically passed via post arguments to the order processing page and those values can be embedded using the following post argument names: "shoppingbasketCreditCardNumber" (Credit Card Number), "shoppingbasketCreditCardMonth" (Expiration Month), "shoppingbasketCreditCardYear" (Expiration Year), shoppingbasketTotal (Order Total). To combine the Expiration Month and Year in the required format (MMYY), those values are first set in a page variable named "CCExpiration" and the variable is then embedded in the mgiCreditCard tag.

Below the credit card authorization, an conditional comparison determines which mgiSendOrder tag is processed based on the credit card authorization. If the order is authorized, it is sent via mgiSendOrder to "orders@domain.com" and the message "Your order has been processed. You should receive the order within 5 business days" is displayed. If the order is not authorized for any reason, it is sent via mgiSendOrder to "errors@domain.com" for manual processing and the message "We have experienced an error while processing your order. Your order has been sent and a representative will contact you to resolve this issue as soon as possible." is displayed.

If the payment method is Check or Purchase Order, the order is sent to "orders@domain.com" with the subject "Product Order".

<mgiConditional id="1" lhs={mgiFieldContent name="shoppingBasketPaymentMethod"}
relationship="equals" rhs="creditCard">
<mgiSet name="CCExpiration">
<mgiFieldContent name="shoppingBasketCreditCardMonth">
<mgiFieldContent name="shoppingBasketCreditCardYear">
</mgiSet>

<mgiSet name="CCAuthorization">
<mgiCreditCard function="Authorize" merchantHandle="GardenCoHandle"
accountNumber={mgiFieldContent name="shoppingBasketCreditCardNumber"} 
expirationDate={mgiGet name="CCExpiration"} 
chargeAmount={mgiFieldContent name="shoppingBasketTotal"}
chargeDescription="Garden Supplies">
</mgiSet>

<mgiConditional id="2" lhs={mgiGet name="CCAuthorization"} 
relationship="equals" rhs="Authorized">

<mgiSendOrder to="orders@domain.com" 
from="webmaster@domain.com" 
mailServer="mail.domain.com"
subject="Product Order" taxRate=".06" state="North Carolina">

Your order has been processed. You should receive the order 
within 5 business days.

<mgiElse id="2">

<mgiSendOrder to="errors@domain.com" 
from="webmaster@domain.com" 
mailServer="mail.domain.com"
subject="Order Authorization Error" taxRate=".06" state="North Carolina">

We have experienced an error while processing your order. Your 
order has been sent and a representative will contact you to 
resolve this issue as soon as possible.

</mgiConditional>
<mgiElse id="1">

<mgiSendOrder to="orders@domain.com" 
from="webmaster@domain.com" 
mailServer="mail.domain.com"
subject="Product Order" taxRate=".06" state="North Carolina">

</mgiConditional>


Suggested Usage

  • Order Processing


[Return to the Referencing MGI Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]