public function testAll()
 {
   // 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();
   
   // Update customer profile
   $customerProfile->description = "New description";
   $customerProfile->email = "*****@*****.**";
   $response = $request->updateCustomerProfile($customerProfileId, $customerProfile);
   $this->assertTrue($response->isOk());
   
   // Add payment profile.
   $paymentProfile = new AuthorizeNetPaymentProfile;
   $paymentProfile->customerType = "individual";
   $paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
   $paymentProfile->payment->creditCard->expirationDate = "2015-10";
   $response = $request->createCustomerPaymentProfile($customerProfileId, $paymentProfile);
   $this->assertTrue($response->isOk());
   $paymentProfileId = $response->getPaymentProfileId();
   
   // Update payment profile.
   $paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
   $paymentProfile->payment->creditCard->expirationDate = "2017-11";
   $response = $request->updateCustomerPaymentProfile($customerProfileId,$paymentProfileId, $paymentProfile);
   $this->assertTrue($response->isOk());
   
   // Add plugins_shipping address.
   $address = new AuthorizeNetAddress;
   $address->firstName = "john";
   $address->lastName = "Doe";
   $address->company = "John Doe Company";
   $address->address = "1 Main Street";
   $address->city = "Boston";
   $address->state = "MA";
   $address->zip = "02412";
   $address->country = "USA";
   $address->phoneNumber = "555-555-5555";
   $address->faxNumber = "555-555-5556";
   $response = $request->createCustomerShippingAddress($customerProfileId, $address);
   $this->assertTrue($response->isOk());
   $customerAddressId = $response->getCustomerAddressId();
   
   // Update plugins_shipping address.
   $address->address = "2 First Street";
   $response = $request->updateCustomerShippingAddress($customerProfileId, $customerAddressId, $address);
   $this->assertTrue($response->isOk());
   
   // Create Auth & Capture Transaction
   $transaction = new AuthorizeNetTransaction;
   $transaction->amount = "9.79";
   $transaction->customerProfileId = $customerProfileId;
   $transaction->customerPaymentProfileId = $paymentProfileId;
   $transaction->customerShippingAddressId = $customerAddressId;
   
   $lineItem              = new AuthorizeNetLineItem;
   $lineItem->itemId      = "4";
   $lineItem->name        = "Cookies";
   $lineItem->description = "Chocolate Chip";
   $lineItem->quantity    = "4";
   $lineItem->unitPrice   = "1.00";
   $lineItem->taxable     = "true";
   
   $lineItem2             = new AuthorizeNetLineItem;
   $lineItem2->itemId     = "4";
   $lineItem2->name       = "Cookies";
   $lineItem2->description= "Peanut Butter";
   $lineItem2->quantity   = "4";
   $lineItem2->unitPrice  = "1.00";
   $lineItem2->taxable    = "true";
   
   $transaction->lineItems[] = $lineItem;
   $transaction->lineItems[] = $lineItem2;
   
   
   $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
   $this->assertTrue($response->isOk());
   $transactionResponse = $response->getTransactionResponse();
   $this->assertTrue($transactionResponse->approved);
   $transactionId = $transactionResponse->transaction_id;
   
   // Void the transaction
   $transaction = new AuthorizeNetTransaction;
   $transaction->transId = $transactionId;
   $response = $request->createCustomerProfileTransaction("Void", $transaction);
   $this->assertTrue($response->isOk());
   $transactionResponse = $response->getTransactionResponse();
   $this->assertTrue($transactionResponse->approved);
   
       
   // Delete Shipping Address
   $response = $request->deleteCustomerShippingAddress($customerProfileId, $customerAddressId);
   $this->assertTrue($response->isOk());
   
   // Delete payment profile.
   $response = $request->deleteCustomerPaymentProfile($customerProfileId, $paymentProfileId);
   $this->assertTrue($response->isOk());
   
   
   // Delete the profile id for future testing.
   $response = $request->deleteCustomerProfile($customerProfileId);
   $this->assertTrue($response->isOk());
 }
    $errorMsg = '';
    $code = ANet_Response_getMessageCode($response);
    switch ($code) {
        case 'E00027':
            $msg = ANet_Response_getMessageText($response);
            switch ($msg) {
                case 'A duplicate transaction has been submitted.':
                    // Authorize.net will deny transactions for identical
                    // amounts that are submitted within two minutes of
                    // each other
                    $errorMsg = 'You are submitting orders too rapidly and have ' . 'triggered the duplicate transaction prevention ' . 'mechanisms with the payment gateway. We ' . 'apologize for the inconvenience. Please wait ' . 'two minutes and try again.';
                    break;
                case 'The credit card number is invalid.':
                    $errorMsg = 'Your payment information was declined by ' . 'the payment gateway. Please verify you ' . 'have entered your information correctly ' . 'and try again.';
                    // deletes the invalid payment profile
                    $response = $request->deleteCustomerPaymentProfile($customerProfileId, $paymentProfileId);
                    break;
                default:
                    $errorMsg = $code . ': ' . $msg;
                    break;
            }
            break;
        default:
            $errorMsg = $code . ': ' . ANet_Response_getMessageText($response);
            break;
    }
    throw new Exception($errorMsg);
}
// gets the transaction ID to save in the subscription table
$transactionResponse = $response->getTransactionResponse();
$transactionId = $transactionResponse->transaction_id;
Esempio n. 3
0
 function deletePay($id)
 {
     $tmpcim = new AuthorizeNetCIM();
     $response = $tmpcim->deleteCustomerPaymentProfile($this->CIM_ID, $id);
     if ($response->isOk) {
         return false;
     } else {
         return $response->getErrorMessage();
     }
 }
Esempio n. 4
0
 /**
  * Deletes a payment method.
  *
  * @return bool
  */
 public function delete()
 {
     if (!($id = $this->id())) {
         return false;
     }
     if (!($customer_gateway_id = $this->data('customer_id'))) {
         return false;
     }
     $request = new AuthorizeNetCIM();
     $response = $request->deleteCustomerPaymentProfile($customer_gateway_id, $id);
     if (!$response->isOk()) {
         Log::error('Unable to delete Authorize.net payment method.');
         return false;
     }
     return true;
 }