Esempio n. 1
0
 /**
  * Finds a single instance.
  * 
  * @param int|array $options Instance identifier or filter data.
  *
  * @return array|null
  */
 public function find_one($options = array())
 {
     $customer_gateway_id = Service_Customer_Gateway::external_id($this->driver->customer, $this->driver->gateway);
     if (!$customer_gateway_id) {
         return null;
     }
     if (is_numeric($options)) {
         $payment_method_id = $options;
     }
     $request = new AuthorizeNetCIM();
     $response = $request->getCustomerPaymentProfile($customer_gateway_id, $payment_method_id);
     if (!$response->isOk()) {
         Log::error('Unable to retrieve Authorize.net payment method.');
         return null;
     }
     $credit_card = $response->xml->paymentProfile->payment->creditCard;
     return array('id' => $response->getPaymentProfileId(), 'customer_id' => $customer_gateway_id, 'account' => '****' . substr($credit_card->cardNumber, -4));
 }
 public function testUpdateCustomerPaymentProfile()
 {
     // 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();
     // 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();
     $request = new AuthorizeNetCIM();
     $response = $request->getCustomerPaymentProfile($customerProfileId, $paymentProfileId);
     if ($response->isOk()) {
         $ppp = $response->getPaymentProfileId();
         $newPaymentProfile = new AuthorizeNetPaymentProfile();
         $newPaymentProfile->customerType = "individual";
         $newPaymentProfile->payment->creditCard->cardNumber = "4007000000000027";
         $newPaymentProfile->payment->creditCard->expirationDate = "2018-08";
         $request = new AuthorizeNetCIM();
         $response = $request->updateCustomerPaymentProfile($customerProfileId, $paymentProfileId, $newPaymentProfile);
     }
     $this->assertTrue($response->isOk());
 }