Esempio n. 1
0
 /**
  * Creates a new payment method.
  *
  * @param array $data The data to use to create the payment method.
  *
  * @return int|bool
  */
 public function create(array $data)
 {
     $customer_gateway_id = Service_Customer_Gateway::external_id($this->driver->customer, $this->driver->gateway);
     if (!$customer_gateway_id) {
         return false;
     }
     if (!($credit_card = Arr::get($data, 'account'))) {
         return false;
     }
     if (!($contact = Arr::get($data, 'contact'))) {
         return false;
     }
     $credit_card['expiration_month'] = strlen($credit_card['expiration_month']) == 2 ? $credit_card['expiration_month'] : '0' . $credit_card['expiration_month'];
     $credit_card['expiration_year'] = strlen($credit_card['expiration_year']) == 4 ? $credit_card['expiration_year'] : '20' . $credit_card['expiration_year'];
     if (!$this->auth($credit_card)) {
         return false;
     }
     $request = new AuthorizeNetCIM();
     $payment_profile = new AuthorizeNetPaymentProfile();
     $payment_profile->payment->creditCard->cardNumber = preg_replace('/\\D+/', '', $credit_card['number']);
     $payment_profile->payment->creditCard->expirationDate = $credit_card['expiration_year'] . '-' . $credit_card['expiration_month'];
     //$payment_profile->payment->creditCard->cardCode = $credit_card['cvv_code'];
     $payment_profile->billTo->firstName = Arr::get($contact, 'first_name', '');
     $payment_profile->billTo->lastName = Arr::get($contact, 'last_name', '');
     $payment_profile->billTo->address = Arr::get($contact, 'address', '') . Arr::get($contact, 'address2', '');
     $payment_profile->billTo->city = Arr::get($contact, 'city', '');
     $payment_profile->billTo->state = Arr::get($contact, 'state', '');
     $payment_profile->billTo->zip = Arr::get($contact, 'zip', '');
     $payment_profile->billTo->country = Arr::get($contact, 'country', '');
     $payment_profile->billTo->phoneNumber = Arr::get($contact, 'phone', '');
     $response = $request->createCustomerPaymentProfile($customer_gateway_id, $payment_profile);
     if (!$response->isOk()) {
         Log::error('Unable to create Authorize.net payment method.');
         return false;
     }
     return $response->getPaymentProfileId();
 }
 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());
 }
            $isMatch = true;
            $paymentProfileId = (string) $paymentProfile->customerPaymentProfileId;
        }
    }
    // creates a new payment profile if there is not a match
    if (!$isMatch) {
        $paymentProfile = new AuthorizeNetPaymentProfile();
        $paymentProfile->payment->creditCard->cardNumber = $subCardnumber;
        $paymentProfile->payment->creditCard->expirationDate = $subCardExpDate;
        $paymentProfile->billTo->firstName = $subFName;
        $paymentProfile->billTo->lastName = $subLName;
        $paymentProfile->billTo->address = $subAddress;
        $paymentProfile->billTo->city = $subCity;
        $paymentProfile->billTo->state = $subState;
        $paymentProfile->billTo->zip = $subZip;
        $response = $request->createCustomerPaymentProfile($customerProfileId, $paymentProfile);
        if (ANet_Response_getResultCode($response) == 'Error') {
            $e = ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response);
            throw new Exception($e);
        }
        $paymentProfileId = (string) $response->xml->customerPaymentProfileId;
    }
}
/*
 * creates a new "Auth & Capture" transaction with the customer
 * profile ID and payment profile ID selected or created above.
 * An "Auth & Capture" transaction completes both the authorization
 * of the payment information and the transfer of funds in one call.
 */
$transaction = new AuthorizeNetTransaction();
$transaction->amount = $subAmount;