Ejemplo n.º 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;
 }
Ejemplo n.º 2
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();
 }