public function testGetCustomerProfile()
 {
     // Create new customer profile
     $request = new AuthorizeNetCIM();
     $customerProfile = new AuthorizeNetCustomer();
     $customerProfile->description = "Description of customer";
     $customerProfile->merchantCustomerId = time() . rand(1, 10);
     $customerProfile->email = "*****@*****.**";
     $response = $request->createCustomerProfile($customerProfile);
     $this->assertTrue($response->isOk());
     $customerProfileId = $response->getCustomerProfileId();
     $response = $request->getCustomerProfile($customerProfileId);
     $this->assertTrue($response->isOk());
 }
Exemple #2
0
 public static function getCardProfiles($customerProfileId)
 {
     $paymentProfiles = array();
     $request = new AuthorizeNetCIM();
     $request->setSandbox(SANDBOX_MODE);
     $response = $request->getCustomerProfile($customerProfileId);
     if ($response->isOk()) {
         foreach ($response->xpath('profile/paymentProfiles') as $sequence => $d) {
             //Log::write(json_encode($d));
             $paymentProfiles[] = array('id' => (string) $d->customerPaymentProfileId, 'cardnumber' => (string) $d->payment->creditCard->cardNumber, 'expiration' => (string) $d->payment->creditCard->expirationDate);
         }
     }
     if ($response->isError()) {
         Log::write(__METHOD__ . ' ' . $response->getMessageCode() . ': ' . $response->getMessageText());
     }
     return $paymentProfiles;
 }
    if (ANet_Response_getResultCode($response) == 'Error') {
        $e = ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response);
        throw new Exception($e);
    }
    // gets the customer profile ID and payment profile ID from the response
    $customerProfileId = $response->getCustomerProfileId();
    $paymentProfileId = $response->getCustomerPaymentProfileIds();
    // updates the database with the new Authorize.net customer profile ID
    $tbl = TBL_COLLEGE_COACH_REGISTER;
    $data = array('fldANetCustomerProfileId' => $customerProfileId);
    $where = 'fldId=' . $fldId;
    $affectedRows = $db1->updateRec($tbl, $data, $where);
} else {
    // gets all existing payment profiles associated with the customer profile
    $request = new AuthorizeNetCIM();
    $response = $request->getCustomerProfile($customerProfileId);
    if (ANet_Response_getResultCode($response) == 'Error') {
        $e = ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response);
        throw new Exception($e);
    }
    $paymentProfiles = $response->xml->profile->paymentProfiles;
    // gets the last four digits of the provided card number
    $subLastFour = substr($subCardnumber, -4);
    // compares the last four digits of the provided card number against all
    // card numbers associated with the customer profile. If match is found,
    // the matched payment profile is used for the transaction
    $isMatch = false;
    foreach ($paymentProfiles as $paymentProfile) {
        $profileCard = (string) $paymentProfile->payment->creditCard->cardNumber;
        if ($subLastFour == substr($profileCard, -4)) {
            $isMatch = true;