예제 #1
0
 /**
  * Creates a new instance.
  *
  * @param $data New instance data.
  *
  * @return 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 (!($payment_method = Arr::get($data, 'payment_method'))) {
         return false;
     }
     if (!($amount = Arr::get($data, 'amount'))) {
         return false;
     }
     $request = new AuthorizeNetCIM();
     $transaction = new AuthorizeNetTransaction();
     $transaction->amount = $amount;
     $transaction->customerProfileId = $customer_gateway_id;
     $transaction->customerPaymentProfileId = $payment_method->external_id;
     // AuthOnly or AuthCapture
     $response = $request->createCustomerProfileTransaction('AuthCapture', $transaction);
     if (!$response->isOk()) {
         Log::error('Unable to create Authorize.net transaction.');
         return false;
     }
     $response = $response->getTransactionResponse();
     if (empty($response->transaction_id)) {
         return false;
     }
     return $response->transaction_id;
 }
 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());
 }
 $fldPaymentProfileId = $db->f('fldPaymentProfileId');
 // gets the customer profile Id
 $query = "SELECT fldFirstName,fldLastName," . "fldANetCustomerProfileId,fldEmail FROM " . TBL_COLLEGE_COACH_REGISTER . " WHERE fldId={$fldCoach}";
 $db1->query($query);
 $db1->next_record();
 $fldFirstName = $db1->f('fldFirstName');
 $fldLastName = $db1->f('fldLastName');
 $fldCustomerProfileId = $db1->f('fldANetCustomerProfileId');
 $fldEmail = $db1->f('fldEmail');
 // attempts to charge the user for the subscription
 $transaction = new AuthorizeNetTransaction();
 $transaction->amount = $fldAmount;
 $transaction->customerProfileId = $fldCustomerProfileId;
 $transaction->customerPaymentProfileId = $fldPaymentProfileId;
 $request = new AuthorizeNetCIM();
 $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
 // if the transaction fails, cancel the subscription
 if (ANet_Response_getResultCode($response) == 'Error') {
     $data = array('fldActive' => 0, 'fldCancelDate' => $today, 'fldCancelReasonOther' => 'Automatic renewal failed (' . ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response) . ')');
     $db1->updateRec(TBL_COLLEGE_SUBSCRIPTION, $data, 'fldId=' . $fldId);
     // gets the active number of subscriptions for the current coach
     $query = "SELECT COUNT(*) AS subsCount FROM " . TBL_COLLEGE_SUBSCRIPTION . " WHERE fldActive=1 AND fldCoach=" . $fldCoach;
     $db1->query($query);
     $db1->next_record();
     $subsCount = $db1->f('subsCount');
     // increments the coach's cancel count by 1. If the
     // coach has no subscriptions now that this subscription
     // is canceled, set fldSubscribe to 0
     $query = "SELECT fldCancelCount FROM " . TBL_COLLEGE_COACH_REGISTER . " WHERE fldId=" . $fldCoach;
     $db1->query($query);
     $db1->next_record();
예제 #4
0
파일: anet.class.php 프로젝트: badtux/pmg
 public static function doTransaction($type, $transactionData = array())
 {
     $request = new AuthorizeNetCIM();
     $requestAim = new AuthorizeNetAIM();
     Log::write(__METHOD__ . ' sandbox ' . (int) SANDBOX_MODE);
     $request->setSandbox(SANDBOX_MODE);
     $transaction = new AuthorizeNetTransaction();
     $libAnetResponse = new Lib_Anet_Response();
     switch ($type) {
         case self::$TRANS_AUTHONLY:
             $amount = $customer_profile_id = $payment_profile_id = $invoice_id = null;
             extract($transactionData, EXTR_OVERWRITE);
             Log::write(__METHOD__ . ' cp :' . $customer_profile_id . ' pp :' . $payment_profile_id . ' inv :' . $invoice_id . ' amt :' . $amount);
             $cps = Lib_Anet::getCardProfiles($customer_profile_id);
             $transaction->amount = $amount;
             $transaction->customerProfileId = $customer_profile_id;
             $transaction->customerPaymentProfileId = $payment_profile_id;
             $transaction->order->invoiceNumber = $invoice_id;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHONLY, $transaction);
             //	$request->createCustomerProfileTransaction($transactionType, $transaction);
             if ($response->isOk()) {
                 Log::write(__METHOD__ . ' ok');
                 $transactionResponse = $response->getTransactionResponse();
                 $libAnetResponse->state = true;
                 $libAnetResponse->transaction_id = $transactionResponse->transaction_id;
                 $libAnetResponse->authorization_code = $transactionResponse->authorization_code;
                 $libAnetResponse->message = $transactionResponse->response_reason_text;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
                 $libAnetResponse->last_digit = trim(str_replace('X', '', $transactionResponse->account_number));
             }
             if ($response->isError()) {
                 Log::write(__METHOD__ . ' err');
                 $libAnetResponse->state = false;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             Log::write(__METHOD__ . ' ' . $response->getMessageCode() . ' ' . $response->getMessageText());
             Log::write(__METHOD__ . ' ' . json_encode($libAnetResponse));
             if ($libAnetResponse->text == 'A duplicate transaction has been submitted.') {
                 $libAnetResponse->text = 'Try again in 2 minutes';
             }
             return $libAnetResponse;
             break;
         case self::$TRANS_PRIORAUTHCAPTURE:
             $transaction_id = $amount = null;
             extract($transactionData, EXTR_OVERWRITE);
             $transaction->transId = $transaction_id;
             $transaction->amount = $amount;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_PRIORAUTHCAPTURE, $transaction);
             if ($response->isOk()) {
                 $transactionResponse = $response->getTransactionResponse();
                 $libAnetResponse->state = true;
                 $libAnetResponse->transaction_id = $transactionResponse->transaction_id;
                 $libAnetResponse->authorization_code = $transactionResponse->authorization_code;
                 $libAnetResponse->message = $transactionResponse->response_reason_text;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             if ($response->isError()) {
                 $libAnetResponse->state = false;
                 /*$returnResponse->message = $transactionResponse->response_reason_text;*/
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             return $libAnetResponse;
             break;
         case self::$TRANS_AUTHCAPTURE:
             $amount = $customer_profile_id = $payment_profile_id = null;
             extract($transactionData, EXTR_OVERWRITE);
             $transaction->amount = $amount;
             $transaction->customerProfileId = $customer_profile_id;
             $transaction->customerPaymentProfileId = $payment_profile_id;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHCAPTURE, $transaction);
             if ($response->isOk()) {
                 $transactionResponse = $response->getTransactionResponse();
                 $libAnetResponse->state = true;
                 $libAnetResponse->transaction_id = $transactionResponse->transaction_id;
                 $libAnetResponse->authorization_code = $transactionResponse->authorization_code;
                 $libAnetResponse->message = $transactionResponse->response_reason_text;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
                 $libAnetResponse->last_digit = trim(str_replace('X', '', $transactionResponse->account_number));
             }
             if ($response->isError()) {
                 $libAnetResponse->state = false;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             return $libAnetResponse;
             break;
         case self::$TRANS_CREDIT:
             $amount = $customerProfileId = $paymentProfileId = null;
             $transaction->amount = $transactionData->amount;
             $requestAim->setSandbox(SANDBOX_MODE);
             $response = $requestAim->credit($transactionData->id, $transactionData->amount, $transactionData->lfor);
             return true;
             if (!$response->error) {
                 return true;
             } else {
                 throw new Exception($response->response_reason_text, 512);
             }
             break;
         case self::$TRANS_VOID:
             $amount = $customer_profile_id = $payment_profile_id = $invoice_id = null;
             extract($transactionData, EXTR_OVERWRITE);
             $transaction->amount = $amount;
             $transaction->customerProfileId = $customer_profile_id;
             $transaction->customerPaymentProfileId = $payment_profile_id;
             $transaction->order->invoiceNumber = $invoice_id;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHONLY, $transaction);
             break;
     }
 }