Ejemplo n.º 1
0
 /**
  * Updates a payment method.
  *
  * @param array $data The data to use to update the payment method.
  *
  * @return bool
  */
 public function update(array $data)
 {
     if (!($id = $this->id())) {
         return false;
     }
     if (!($customer_gateway_id = $this->data('customer_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->updateCustomerPaymentProfile($customer_gateway_id, $id, $payment_profile);
     if (!$response->isOk()) {
         Log::error('Unable to update Authorize.net payment method.');
         return false;
     }
     return true;
 }
 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());
 }
<?php

require_once 'anet_php_sdk/AuthorizeNet.php';
require_once 'AuthorizeNetMerchantAccount.php';
// gets the Authorize.net payment profile ID created
// for the subscription from the database
$queryString = "SELECT `%s` FROM `%s` WHERE fldId='%s'";
$query = sprintf($queryString, 'fldPaymentProfileId', TBL_COLLEGE_SUBSCRIPTION, $subId);
$db1->query($query);
$db1->next_record();
$paymentProfileId = $db1->f('fldPaymentProfileId');
// updates the payment profile with the new information
$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;
$request = new AuthorizeNetCIM();
$response = $request->updateCustomerPaymentProfile($customerProfileId, $paymentProfileId, $paymentProfile);
if (ANet_Response_getResultCode($response) == 'Error') {
    $e = ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response);
    throw new Exception($e);
}