/**
  * Creates and returns a credit card object if it is valid
  *
  * $data = array(
  *		'first_name' => 'John',
  *		'last_name' => 'Doe',
  *		'number' => '5105105105105100',
  *		'month' => '12',
  *		'year' => '2012',
  *		'verification_value' => '123',
  *		'type' => 'master',
  *	);
  *
  * @param string $data 
  * @return $creditCard Merchant_Billing_CreditCard or false if the card is invalid
  */
 public function creditCard($data)
 {
     if ($data instanceof Merchant_Billing_CreditCard) {
         if ($data->is_valid()) {
             return $data;
         } else {
             return false;
         }
     } else {
         if (isset($data['credit_card'])) {
             $data = $data['credit_card'];
         }
         $creditCard = new Merchant_Billing_CreditCard($data);
         if ($creditCard->is_valid()) {
             return $creditCard;
         } else {
             return false;
         }
     }
 }
Example #2
0
 /**
  *
  * @param Merchant_Billing_CreditCard $creditcard
  */
 private function add_creditcard(Merchant_Billing_CreditCard $creditcard)
 {
     $this->post['CardName'] = $creditcard->name();
     $this->post['CardNumber'] = $creditcard->number;
     $this->post['ExpiryDateMM'] = $this->cc_format($creditcard->month, 'two_digits');
     $this->post['ExpiryDateYY'] = $this->cc_format($creditcard->year, 'two_digits');
     if ($this->requires_start_date_or_issue_number($creditcard)) {
         $this->post['StartDateMM'] = $this->cc_format($creditcard->start_month, "two_digits");
         $this->post['StartDateYY'] = $this->cc_format($creditcard->start_year, "two_digits");
         $this->post['IssueNumber'] = $creditcard->issue_number;
         $this->post['CV2'] = $creditcard->verification_value;
     }
 }
Example #3
0
<?php

require_once '../../lib/merchant.php';
require_once '../login.php';
Merchant_Billing_Base::mode('test');
# Remove this on production mode
#Alternative way to get a gateway instanse.
$gateway = Merchant_Billing_Base::gateway('authorize_net', array('login' => AUTH_NET_LOGIN, 'password' => AUTH_NET_PASS));
$cc = new Merchant_Billing_CreditCard(array("first_name" => "John", "last_name" => "Doe", "number" => "4111111111111111", "month" => "01", "year" => "2015", "verification_value" => "000"));
$options = array('order_id' => 'REF' . $gateway->generate_unique_id(), 'description' => 'Autorize.net Test Transaction', 'address' => array('address1' => '1234 Street', 'zip' => '98004', 'state' => 'WA'));
try {
    if (false == $cc->is_valid()) {
        var_dump($cc->errors());
    } else {
        $response = $gateway->purchase("0.01", $cc, $options);
        echo $response->message();
    }
} catch (Exception $e) {
    echo $e->getMessage();
}
Example #4
0
<?php

require_once '../../lib/merchant.php';
require_once '../login.php';
Merchant_Billing_Base::mode('test');
# Remove this on production mode
#Alternative way to get a gateway instanse.
$gateway = Merchant_Billing_Base::gateway('authorize_net', array('login' => AUTH_NET_LOGIN, 'password' => AUTH_NET_PASS));
$cc = new Merchant_Billing_CreditCard(array("first_name" => "John", "last_name" => "Doe", "number" => "4111111111111111", "month" => "01", "year" => "2015", "verification_value" => "000"));
$options = array('order_id' => 'REF' . $gateway->generate_unique_id(), 'description' => '', 'length' => '1', 'unit' => 'months', 'start_date' => '2010-09-11', 'occurrences' => '10', 'billing_address' => array('first_name' => 'John', 'last_name' => 'Doe', 'address1' => '1234 Street', 'zip' => '98004', 'state' => 'WA'));
try {
    if (false == $cc->is_valid()) {
        var_dump($cc->errors());
    } else {
        $response = $gateway->recurring("1.00", $cc, $options);
        if ($response->success()) {
            echo " Subscription id: " . $response->subscription_id;
        } else {
            echo $response->message();
        }
    }
} catch (Exception $e) {
    echo $e->getMessage();
}
    /**
     *
     * @param Merchant_Billing_CreditCard $creditcard
     */
    private function add_creditcard(Merchant_Billing_CreditCard $creditcard)
    {
        $cardholdername = strtoupper($creditcard->name());
        $this->post .= <<<XML
      <ns:CardInfo>
        <ns:CardType>{$this->CARD_MAPPINGS[$creditcard->type]}</ns:CardType>
        <ns:CardNumber>{$creditcard->number}</ns:CardNumber>
        <ns:CardHolderName>{$cardholdername}</ns:CardHolderName>
        <ns:ExpirationMonth>{$creditcard->month}</ns:ExpirationMonth>
        <ns:ExpirationYear>{$creditcard->year}</ns:ExpirationYear>
        <ns:Cvv2>{$creditcard->verification_value}</ns:Cvv2>
        <ns:Aid/>
        <ns:Emv/>
        <ns:PinBlock/>
      </ns:CardInfo>
XML;
    }
 public function matchCardType(&$model, $check, $numberField)
 {
     return Merchant_Billing_CreditCard::matching_type($this->data[$model->alias][$numberField], array_pop($check));
 }