private function charge_credit_card()
 {
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($this->api_login_id);
     $merchantAuthentication->setTransactionKey($this->api_transaction_key);
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($this->card_number);
     $creditCard->setExpirationDate($this->expiration_year . '-' . $this->expiration_month);
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     // Order info
     $order = new AnetAPI\OrderType();
     $order->setInvoiceNumber($this->invoice_number);
     $order->setDescription(get_bloginfo('name'));
     $cart_contents = $this->purchase_log->get_cart_contents();
     $lineitems = array();
     // Line Item Info
     foreach ($cart_contents as $index => $item) {
         // this is for the product options support that can be used in place of variations
         if (defined('OPTION_BASE')) {
             $options = wpsc_get_cart_item_meta($item->id, OPTION_BASE, true);
             if (!empty($options)) {
                 $options_message = strip_tags($options->message());
             }
         }
         $custom_description = $item->name . ' ' . $options_message . ' ' . $item->custom_message;
         $lineitems[$index] = new AnetAPI\LineItemType();
         $lineitems[$index]->setItemId($item->prodid);
         $lineitems[$index]->setName(substr($item->name, 0, 31));
         $lineitems[$index]->setDescription(substr($custom_description, 0, 255));
         $lineitems[$index]->setQuantity($item->quantity);
         $lineitems[$index]->setUnitPrice($this->force_two_decimals($item->price));
         $lineitems[$index]->setTaxable(0.0 != floatval($item->tax_charged));
     }
     // Tax info
     $tax = new AnetAPI\ExtendedAmountType();
     $tax->setName("Sales Tax");
     $tax->setAmount($this->force_two_decimals($this->purchase_log->get('wpec_taxes_total')));
     $tax->setDescription("Sales Tax");
     // Customer info
     $customer = new AnetAPI\CustomerDataType();
     $wp_user = get_user_by('email', $this->checkout_data->get('billingemail'));
     if ($wp_user) {
         $customer->setId($wp_user->ID);
     }
     $customer->setEmail($this->checkout_data->get('billingemail'));
     // PO Number
     $ponumber = $this->checkout_data->get('billingponumber');
     //Ship To Info
     $shipto = new AnetAPI\NameAndAddressType();
     $shipto->setFirstName($this->checkout_data->get('shippingfirstname'));
     $shipto->setLastName($this->checkout_data->get('shippinglastname'));
     //		$shipto->setCompany( $this->checkout_data->get( 'shippingcompany') );
     $shipto->setAddress($this->checkout_data->get('shippingaddress'));
     $shipto->setCity($this->checkout_data->get('shippingcity'));
     $shipto->setState($this->checkout_data->get('shippingstate'));
     $shipto->setZip($this->checkout_data->get('shippingpostcode'));
     $shipto->setCountry($this->checkout_data->get('shippingcountry'));
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($this->checkout_data->get('billingfirstname'));
     $billto->setLastName($this->checkout_data->get('billinglastname'));
     //		$billto->setCompany(  $this->checkout_data->get( 'billingcompany') );
     $billto->setAddress($this->checkout_data->get('billingaddress'));
     $billto->setCity($this->checkout_data->get('billingcity'));
     $billto->setState($this->checkout_data->get('billingstate'));
     $billto->setZip($this->checkout_data->get('billingpostcode'));
     $billto->setCountry($this->checkout_data->get('billingcountry'));
     $billto->setPhoneNumber($this->checkout_data->get('billingphone'));
     //create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     foreach ($lineitems as $lineitem) {
         $transactionRequestType->addToLineItems($lineitem);
     }
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($this->force_two_decimals($this->purchase_log->get('totalprice')));
     $transactionRequestType->setTax($tax);
     $transactionRequestType->setPayment($paymentOne);
     $transactionRequestType->setOrder($order);
     if (!empty($ponumber)) {
         $transactionRequestType->setPoNumber($ponumber);
     }
     $transactionRequestType->setCustomer($customer);
     $transactionRequestType->setBillTo($billto);
     $transactionRequestType->setShipTo($shipto);
     if (!empty($_SERVER['REMOTE_ADDR'])) {
         $transactionRequestType->setCustomerIP($_SERVER['REMOTE_ADDR']);
     }
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     if ($this->sandbox_mode) {
         $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     } else {
         $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     }
     $result = false;
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         if ($tresponse != null) {
             // see http://developer.authorize.net/api/reference/ for definitions
             if ($tresponse->getResponseCode() == "1") {
                 // 1 = Approved
                 $this->set_purchaselog_status(WPSC_Purchase_Log::ACCEPTED_PAYMENT);
                 $result = true;
             } elseif ($tresponse->getResponseCode() == "2") {
                 // 2 = Declined
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 $result = true;
             } elseif ($tresponse->getResponseCode() == "3") {
                 // 3 = Error
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 $result = false;
             } elseif ($tresponse->getResponseCode() == "4") {
                 // 4 = Held for Review
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 $result = true;
             } else {
                 // Unknown transaction code
                 $this->set_purchaselog_status(WPSC_Purchase_Log::INCOMPLETE_SALE);
                 error_log(__CLASS__ . '::' . __FUNCTION__ . ' ' . "ERROR: Charge Credit Card ERROR : Unknown transaction response code");
             }
             wpsc_update_purchase_meta($this->invoice_number, 'pbci_auth_net_raw_response', $tresponse);
             $messages = wpsc_get_customer_meta('checkout_misc_error_messages');
             if (!is_array($messages)) {
                 $messages = array();
             }
             // get the transaction error messages
             $transaction_error_messages = $response->getMessages();
             if ($transaction_error_messages) {
                 $transaction_error_messages = $transaction_error_messages->getMessage();
             }
             if (!is_array($transaction_error_messages)) {
                 $transaction_error_messages = array($transaction_error_messages);
             }
             foreach ($transaction_error_messages as $error_message) {
                 $messages[] = $error_message->getText();
             }
             // get the transaction response error messages
             $transaction_errors = $tresponse->getErrors();
             foreach ($transaction_errors as $transaction_error) {
                 $messages[] = $transaction_error->getErrorText();
             }
             wpsc_update_customer_meta('checkout_misc_error_messages', $messages);
             $this->purchase_log->set('transactid', $tresponse->getTransId());
             $this->purchase_log->set('authcode', $tresponse->getAuthCode());
         } else {
             error_log(__CLASS__ . '::' . __FUNCTION__ . ' ' . "ERROR: Charge Credit Card ERROR :  Invalid response");
         }
     } else {
         error_log(__CLASS__ . '::' . __FUNCTION__ . ' ' . "ERROR: Charge Credit card Null response returned");
     }
     $this->purchase_log->save();
     return $result;
 }
Exemplo n.º 2
1
 public static function CreateCustomerProfile(Payload $payload)
 {
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($payload->cardNumber);
     $creditCard->setExpirationDate($payload->expiryDate);
     $paymentCreditCard = new AnetAPI\PaymentType();
     $paymentCreditCard->setCreditCard($creditCard);
     // Create the Bill To info
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($payload->firstName);
     $billto->setLastName($payload->lastName);
     $billto->setCompany($payload->company);
     $billto->setAddress($payload->address);
     $billto->setCity($payload->city);
     $billto->setState($payload->state);
     $billto->setZip($payload->zip);
     $billto->setCountry("USA");
     // Create a Customer Profile Request
     //  1. create a Payment Profile
     //  2. create a Customer Profile
     //  3. Submit a CreateCustomerProfile Request
     //  4. Validate Profiiel ID returned
     $paymentprofile = new AnetAPI\CustomerPaymentProfileType();
     $paymentprofile->setCustomerType('individual');
     $paymentprofile->setBillTo($billto);
     $paymentprofile->setPayment($paymentCreditCard);
     $paymentprofiles[] = $paymentprofile;
     $customerprofile = new AnetAPI\CustomerProfileType();
     $customerprofile->setDescription($payload->description);
     $customerprofile->addToShipToList($billto);
     $merchantCustomerId = time() . rand(1, 150);
     $customerprofile->setMerchantCustomerId($merchantCustomerId);
     $customerprofile->setEmail($payload->email);
     $customerprofile->setPaymentProfiles($paymentprofiles);
     $request = new AnetAPI\CreateCustomerProfileRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setProfile($customerprofile);
     $controller = new AnetController\CreateCustomerProfileController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         return $response;
     } else {
         throw new PaymentErrorException($response->getMessages()->getMessage()[0]->getText());
     }
 }
Exemplo n.º 3
1
 public function cancelSubscription()
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $request = new AnetAPI\ARBCancelSubscriptionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     /*$request->setRefId($refId);*/
     $request->setSubscriptionId($this->getPayload()->subscriptionId);
     $controller = new AnetController\ARBCancelSubscriptionController($request);
     $this->setResponse($controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX));
     if ($this->getResponse() != null && $this->getResponse()->getMessages()->getResultCode() == "Ok") {
         return $this->getResponse();
     } else {
         throw new PaymentErrorException($this->getResponse()->getMessages()->getMessage()[0]->getText());
     }
 }
 public function testCreateTransactionApplePay()
 {
     $merchantAuthentication = new apiContract\MerchantAuthenticationType();
     $merchantAuthentication->setName(self::$LoginName);
     $merchantAuthentication->setTransactionKey(self::$TransactionKey);
     $OpaqueData = new apiContract\OpaqueDataType();
     $OpaqueData->setDataDescriptor("COMMON.APPLE.INAPP.PAYMENT");
     $OpaqueData->setDataValue("eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0=");
     $paymentType = new apiContract\PaymentType();
     $paymentType->setOpaqueData($OpaqueData);
     //create a transaction
     $transactionRequestType = new apiContract\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     // TODO Change to Enum
     $transactionRequestType->setAmount($this->setValidAmount($this->counter));
     $transactionRequestType->setPayment($paymentType);
     $request = new apiContract\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new apiController\CreateTransactionController($request);
     $response = $controller->executeWithApiResponse(self::$TestEnvironment);
     // Handle the response.
     $this->assertNotNull($response, "null response");
     $this->assertNotNull($response->getMessages());
     self::displayMessages($response);
     if ("Ok" != $response->getMessages()->getResultCode()) {
         $this->displayTransactionMessages($response);
         //Ignore assertion for now
         //$this->assertTrue( false, "Should not reach here.");
     } else {
         $this->assertEquals("Ok", $response->getMessages()->getResultCode());
         $this->assertTrue(0 < count($response->getMessages()));
         foreach ($response->getMessages() as $message) {
             $this->assertEquals("I00001", $message->getCode());
             $this->assertEquals("Successful.", $response->getText());
         }
     }
 }
 public function testLogout()
 {
     $this->markTestSkipped('Ignoring for Travis. Will fix after release.');
     //TODO
     $name = defined('AUTHORIZENET_API_LOGIN_ID') && '' != AUTHORIZENET_API_LOGIN_ID ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
     $transactionKey = defined('AUTHORIZENET_TRANSACTION_KEY') && '' != AUTHORIZENET_TRANSACTION_KEY ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
     $merchantAuthentication = new MerchantAuthenticationType();
     $merchantAuthentication->setName($name);
     $merchantAuthentication->setTransactionKey($transactionKey);
     $refId = 'ref' . time();
     $request = new LogoutRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $controller = new LogoutController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     // Handle the response.
     $this->assertNotNull($response, "null response");
     $this->assertNotNull($response->getMessages());
     $this->assertEquals("Ok", $response->getMessages()->getResultCode());
     $this->assertEquals($response->getRefId(), $refId);
     $this->assertTrue(0 < count($response->getMessages()));
     foreach ($response->getMessages() as $message) {
         $this->assertEquals("I00001", $message->getCode());
         $this->assertEquals("Successful.", $response->getText());
     }
 }
 public function __invoke(ContainerInterface $sm)
 {
     $config = $sm->get('config');
     if (!array_key_exists('soliant_payment_authnet', $config) || !array_key_exists('login', $config['soliant_payment_authnet']) || !array_key_exists('key', $config['soliant_payment_authnet'])) {
         throw new OutOfBoundsException('AuthnetPayment authentication key not configured.');
     }
     $merchantAuthentication = new MerchantAuthenticationType();
     $merchantAuthentication->setName($config['soliant_payment_authnet']['login']);
     $merchantAuthentication->setTransactionKey($config['soliant_payment_authnet']['key']);
     return $merchantAuthentication;
 }
 public function testLogout()
 {
     $merchantAuthentication = new apiContract\MerchantAuthenticationType();
     $merchantAuthentication->setName(self::$LoginName);
     $merchantAuthentication->setTransactionKey(self::$TransactionKey);
     $request = new apiContract\LogoutRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($this->refId);
     $controller = new apiController\LogoutController($request);
     $response = $controller->executeWithApiResponse(self::$TestEnvironment);
     // Handle the response.
     $this->assertNotNull($response, "null response");
     $this->assertNotNull($response->getMessages());
     $this->assertEquals("Ok", $response->getMessages()->getResultCode());
     $this->assertEquals($this->refId, $response->getRefId());
     $this->assertTrue(0 < count($response->getMessages()));
     foreach ($response->getMessages() as $message) {
         $this->assertEquals("I00001", $message->getCode());
         $this->assertEquals("Successful.", $response->getText());
     }
 }
 public function testCreateTransactionCreditCard()
 {
     $this->markTestSkipped('Ignoring for Travis. Will fix after release.');
     //TODO
     $name = defined('AUTHORIZENET_API_LOGIN_ID') && '' != AUTHORIZENET_API_LOGIN_ID ? AUTHORIZENET_API_LOGIN_ID : getenv("api_login_id");
     $transactionKey = defined('AUTHORIZENET_TRANSACTION_KEY') && '' != AUTHORIZENET_TRANSACTION_KEY ? AUTHORIZENET_TRANSACTION_KEY : getenv("transaction_key");
     $merchantAuthentication = new MerchantAuthenticationType();
     $merchantAuthentication->setName($name);
     $merchantAuthentication->setTransactionKey($transactionKey);
     $refId = 'ref' . time();
     //create a transaction
     $transactionRequestType = new TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     // TODO Change to Enum
     $transactionRequestType->setAmount($this->setValidAmount($this->counter));
     $transactionRequestType->setPayment($this->paymentOne);
     $transactionRequestType->setOrder($this->orderType);
     $transactionRequestType->setCustomer($this->customerDataOne);
     $transactionRequestType->setBillTo($this->customerAddressOne);
     $request = new CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new CreateTransactionController($request);
     $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     $response = $controller->getApiResponse();
     // Handle the response.
     $this->assertNotNull($response, "null response");
     $this->assertNotNull($response->getMessages());
     $this->assertEquals("Ok", $response->getMessages()->getResultCode());
     $this->assertEquals($response->getRefId(), $refId);
     $this->assertTrue(0 < count($response->getMessages()));
     foreach ($response->getMessages() as $message) {
         $this->assertEquals("I00001", $message->getCode());
         $this->assertEquals("Successful.", $response->getText());
     }
 }
Exemplo n.º 9
0
function refundTransaction($amount)
{
    // Common setup for API credentials
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
    $refId = 'ref' . time();
    // Create the payment data for a credit card
    $creditCard = new AnetAPI\CreditCardType();
    $creditCard->setCardNumber("0015");
    $creditCard->setExpirationDate("XXXX");
    $paymentOne = new AnetAPI\PaymentType();
    $paymentOne->setCreditCard($creditCard);
    //create a transaction
    $transactionRequest = new AnetAPI\TransactionRequestType();
    $transactionRequest->setTransactionType("refundTransaction");
    $transactionRequest->setAmount($amount);
    $transactionRequest->setPayment($paymentOne);
    $request = new AnetAPI\CreateTransactionRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setTransactionRequest($transactionRequest);
    $controller = new AnetController\CreateTransactionController($request);
    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
    if ($response != null) {
        $tresponse = $response->getTransactionResponse();
        if ($tresponse != null && $tresponse->getResponseCode() == "1") {
            echo "Refund SUCCESS: " . $tresponse->getTransId() . "\n";
        } else {
            echo "Refund ERROR : " . $tresponse->getResponseCode() . "\n";
        }
    } else {
        echo "Refund Null response returned";
    }
    return $response;
}
Exemplo n.º 10
0
<?php

//  include (TEMPLATEPATH."/lib/anet_php_sdk/AuthorizeNet.php");
//  include (TEMPLATEPATH."/authorize.php");
require ASBPATH . '/lib/vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("556KThWQ6vf2");
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
$refId = 'ref' . time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2038-12");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Order info
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber("101");
$order->setDescription("Golf Shirts");
// Line Item Info
$lineitem = new AnetAPI\LineItemType();
$lineitem->setItemId("Shirts");
$lineitem->setName("item1");
$lineitem->setDescription("golf shirt");
$lineitem->setQuantity("1");
$lineitem->setUnitPrice(20.95);
$lineitem->setTaxable(false);
Exemplo n.º 11
0
 public function getSubscriptionStatus($subscriptionId, $refId)
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $request = new AnetAPI\ARBGetSubscriptionStatusRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setSubscriptionId($subscriptionId);
     $controller = new AnetController\ARBGetSubscriptionStatusController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         echo "SUCCESS: Subscription Status : " . $response->getStatus() . "\n";
     } else {
         echo "ERROR :  Invalid response\n";
         echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
     }
     return $response;
 }
<?php

require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("3Zw3Ru9nx");
$merchantAuthentication->setTransactionKey("7Tbj6T3a9cPq4A5d");
// An existing payment profile ID for this Merchant name and Transaction key
//
$customerprofileid = "37680862";
$customerpaymentprofileid = "34249159";
$validationmode = "testMode";
$request = new AnetAPI\ValidateCustomerPaymentProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setCustomerProfileId($customerprofileid);
$request->setCustomerPaymentProfileId($customerpaymentprofileid);
$request->setValidationMode($validationmode);
$controller = new AnetController\ValidateCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo $response->getMessages()->getMessage()[0]->getText();
} else {
    echo "ERROR :  Validate Customer Payment Profile: Invalid response\n";
    echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}
Exemplo n.º 13
0
 function refundTransaction()
 {
     $loggedUser = $this->Auth->user();
     //  pr($this->request->data['Transaction']);
     //    exit;
     $this->loadModel('Ticket');
     $this->loadModel('Track');
     $loggedUser = $this->Auth->user();
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     // $merchantAuthentication->setName("95x9PuD6b2"); // testing mode
     $merchantAuthentication->setName("42UHbr9Qa9B");
     // live mode
     // $merchantAuthentication->setTransactionKey("547z56Vcbs3Nz9R9");  // testing mode
     $merchantAuthentication->setTransactionKey("6468X36RkrKGm3k6");
     // live mode
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($this->request->data['Transaction']['card_no']);
     //$creditCard->setCardNumber("0015");
     $dateObj = $this->request->data['Transaction']['exp_date'];
     $this->request->data['Transaction']['exp_date'] = $dateObj['month'] . '/' . substr($dateObj['year'], -2);
     $creditCard->setExpirationDate($this->request->data['Transaction']['exp_date']);
     // $creditCard->setExpirationDate("XXXX");
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     //create a transaction
     $transactionRequest = new AnetAPI\TransactionRequestType();
     $transactionRequest->setTransactionType("refundTransaction");
     $transactionRequest->setAmount($this->request->data['Transaction']['refund_amount']);
     $transactionRequest->setPayment($paymentOne);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequest);
     $controller = new AnetController\CreateTransactionController($request);
     //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     $msg = '';
     $data4transaction['Transaction']['exp_date'] = $this->request->data['Transaction']['exp_date'];
     $data4transaction['Transaction']['card_no'] = $this->request->data['Transaction']['card_no'];
     $data4transaction['Transaction']['user_id'] = $loggedUser['id'];
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         //pr($tresponse); exit;
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             $data4transaction['Transaction']['paid_amount'] = $this->request->data['Transaction']['refund_amount'];
             $data4transaction['Transaction']['package_customer_id'] = $this->request->data['Transaction']['cid'];
             $data4transaction['Transaction']['status'] = 'Refund Successful';
             //   $data4transaction['Transaction']['trx_id'] = $tresponse->getTransId();
             $msg = ' <div class="alert alert-success">
         <button type="button" class="close" data-dismiss="alert"></button>
         <p> <strong>Refund SUCCESS</strong>
             </p> </div>';
             $tdata['Ticket'] = array('content' => 'Refund successfull');
             $tickect = $this->Ticket->save($tdata);
             // Data save in Ticket
             $trackData['Track'] = array('package_customer_id' => $data4transaction['Transaction']['package_customer_id'], 'ticket_id' => $tickect['Ticket']['id'], 'status' => 'closed', 'forwarded_by' => $loggedUser['id']);
             $this->Track->save($trackData);
         } else {
             $data4transaction['Transaction']['paid_amount'] = 0;
             $data4transaction['Transaction']['package_customer_id'] = $this->request->data['Transaction']['cid'];
             $data4transaction['Transaction']['status'] = 'Refund failed';
             $data4transaction['Transaction']['error_msg'] = "Refund ERROR : ";
             //. $tresponse->getResponseCode();
             $msg = ' <div class="alert alert-block alert-danger fade in">
         <button type="button" class="close" data-dismiss="alert"></button>
         <p> <strong>Refund ERROR  ' . '</strong> </p> </div>';
             $tdata['Ticket'] = array('content' => 'Refund failed for Null response');
             //  pr($tdata['Ticket']);exit;
             $tickect = $this->Ticket->save($tdata['Ticket']);
             // Data save in Ticket
             $trackData['Track'] = array('package_customer_id' => $data4transaction['Transaction']['package_customer_id'], 'ticket_id' => $tickect['Ticket']['id'], 'status' => 'closed', 'forwarded_by' => $loggedUser['id']);
             $this->Track->save($trackData);
         }
     } else {
         $data4transaction['Transaction']['paid_amount'] = 0;
         $data4transaction['Transaction']['package_customer_id'] = $this->request->data['Transaction']['cid'];
         $data4transaction['Transaction']['status'] = 'Refund failed';
         $data4transaction['Transaction']['error_msg'] = "Refund Null response returned";
         $msg .= 'Refund failed for Null response';
         $msg = ' <div class="alert alert-block alert-danger fade in">
         <button type="button" class="close" data-dismiss="alert"></button>
         <p> <strong>Refund failed for Null response  </strong> </p> </div>';
         $tdata['Ticket'] = array('content' => 'Transaction ' . ' Refund failed for Null response');
         $tickect = $this->Ticket->save($tdata);
         // Data save in Ticket
         $trackData['Track'] = array('package_customer_id' => $data4transaction['Transaction']['package_customer_id'], 'ticket_id' => $tickect['Ticket']['id'], 'status' => 'open', 'forwarded_by' => $loggedUser['id']);
         $this->Track->save($trackData);
         //            $tdata4ticket['Ticket'] = array('content' => 'Refund for ' . $pc['fname'] . ' ' . $pc['lname'] . ' failed for Charge Credit card Null response');
         //            $tickect = $this->Ticket->save($tdata); // Data save in Ticket
         //            $trackData['Track'] = array(
         //                'package_customer_id' => $cid,
         //                'ticket_id' => $tickect['Ticket']['id'],
         //                'status' => 'open',
         //                'forwarded_by' => $loggedUser['id']
         //            );
         //            $this->Track->save($trackData);
         //  echo "Refund Null response returned";
     }
     $this->loadModel('Transaction');
     //        pr($this->request->data); exit;
     $data4transaction['Transaction']['pay_mode'] = 'refund';
     $this->Transaction->save($data4transaction);
     $this->Session->setFlash($msg);
     return $this->redirect($this->referer());
 }
 protected function processPayment(Application $app, $cardInfo, $amount, $user, $students, $bill_address)
 {
     define("AUTHORIZENET_LOG_FILE", "../authorize.net.log");
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($app['authrize.net.name']);
     $merchantAuthentication->setTransactionKey($app['authrize.net.key']);
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($cardInfo->card_num);
     $creditCard->setExpirationDate($cardInfo->exp);
     $creditCard->setCardCode($cardInfo->code);
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     // Order info
     // $order = new AnetAPI\OrderType();
     // $order->setInvoiceNumber($order->getInvoiceNumber());
     // $order->setDescription('Payment for '.implode(' ', $students));
     // Line Item Info
     // $lineitem = new AnetAPI\LineItemType();
     // $lineitem->setItemId("Shirts");
     // $lineitem->setName("item1");
     // $lineitem->setDescription("golf shirt");
     // $lineitem->setQuantity("1");
     // $lineitem->setUnitPrice(20.95);
     // $lineitem->setTaxable("Y");
     // Tax info
     // $tax =  new AnetAPI\ExtendedAmountType();
     // $tax->setName("level 2 tax name");
     // $tax->setAmount(4.50);
     // $tax->setDescription("level 2 tax");
     // Customer info
     $customer = new AnetAPI\CustomerDataType();
     $customer->setId($user->getUserId());
     $customer->setEmail($user->getEmail());
     // PO Number
     // $ponumber = "15";
     //Ship To Info
     // $shipto = new AnetAPI\NameAndAddressType();
     // $shipto->setFirstName("Bayles");
     // $shipto->setLastName("China");
     // $shipto->setCompany("Thyme for Tea");
     // $shipto->setAddress("12 Main Street");
     // $shipto->setCity("Pecan Springs");
     // $shipto->setState("TX");
     // $shipto->setZip("44628");
     // $shipto->setCountry("USA");
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($user->getFirstName());
     $billto->setLastName($user->getLastName());
     $billto->setCompany("");
     $billto->setAddress($bill_address->getStreet());
     $billto->setCity($bill_address->getCity());
     $billto->setState($bill_address->getState());
     $billto->setZip($bill_address->getZip());
     $billto->setCountry("USA");
     //create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($amount);
     $transactionRequestType->setPayment($paymentOne);
     // $transactionRequestType->setOrder($order);
     // $transactionRequestType->addToLineItems($lineitem);
     // $transactionRequestType->setTax($tax);
     // $transactionRequestType->setPoNumber($ponumber);
     $transactionRequestType->setCustomer($customer);
     $transactionRequestType->setBillTo($billto);
     // $transactionRequestType->setShipTo($shipto);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     if (null != $response) {
         $tresponse = $response->getTransactionResponse();
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             // return array(
             // "AUTH_CODE" => $tresponse->getAuthCode(),
             // "TRANS_ID" => $tresponse->getTransId()
             // );
             return array('approved' => true, 'data' => $tresponse);
         } else {
             return array('approved' => false, 'data' => $tresponse);
         }
     } else {
         return array('approved' => false, 'data' => null);
     }
 }
Exemplo n.º 15
0
 public function process()
 {
     $this->layout = 'ajax';
     //        $this->loadModel('PaidCustomer');
     //        $sql = "SELECT name, transactionkey ,card_no, exp_date FROM paid_customers ";
     //        $cardinfo = $this->PaidCustomer->query($sql);
     //        // Common setup for API credentials
     //        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     //        $merchantAuthentication->setName("95x9PuD6b2"); // testing mode
     //        //$merchantAuthentication->setName("42UHbr9Qa9B"); // live mode
     //        $merchantAuthentication->setTransactionKey("547z56Vcbs3Nz9R9");  // testing mode
     ////        $merchantAuthentication->setTransactionKey("6468X36RkrKGm3k6"); // live mode
     //        $refId = 'ref' . time();
     //
     //        // Create the payment data for a credit card
     //        $creditCard = new AnetAPI\CreditCardType();
     //        $creditCard->setCardNumber("4111111111111111"); // testing
     //        $creditCard->setExpirationDate("2038-12"); // testing
     //
     //      //  $creditCard->setCardNumber("4117733943147221"); // live
     //       // $creditCard->setExpirationDate("07-2019"); //live
     //        $paymentOne = new AnetAPI\PaymentType();
     //        $paymentOne->setCreditCard($creditCard);
     //
     //        // Order info
     //        $order = new AnetAPI\OrderType();
     //        $order->setInvoiceNumber("101");
     //        $order->setDescription("Golf Shirts");
     //
     //        // Line Item Info
     //        $lineitem = new AnetAPI\LineItemType();
     //        $lineitem->setItemId("Shirts");
     //        $lineitem->setName("item1");
     //        $lineitem->setDescription("golf shirt");
     //        $lineitem->setQuantity("1");
     //        $lineitem->setUnitPrice(1.00);
     //        $lineitem->setTaxable(false);
     //
     //        // Tax info
     ////        $tax = new AnetAPI\ExtendedAmountType();
     ////        $tax->setName("level 2 tax name");
     ////        $tax->setAmount(4.50);
     ////        $tax->setDescription("level 2 tax");
     //        // Customer info
     ////        $customer = new AnetAPI\CustomerDataType();
     ////        $customer->setId("15");
     ////        $customer->setEmail("*****@*****.**");
     //        // PO Number
     //        $ponumber = "15";
     //        //Ship To Info
     //        $shipto = new AnetAPI\NameAndAddressType();
     //        //$shipto->setFirstName("Bayles");
     //        // $shipto->setLastName("China");
     //        // $shipto->setCompany("Thyme for Tea");
     //        //  $shipto->setAddress("12 Main Street");
     //        // $shipto->setCity("Pecan Springs");
     //        //  $shipto->setState("TX");
     //        $shipto->setZip("11554");
     //        //  $shipto->setCountry("USA");
     //        // Bill To
     ////        $billto = new AnetAPI\CustomerAddressType();
     ////        $billto->setFirstName("Ellen");
     ////        $billto->setLastName("Johnson");
     ////        $billto->setCompany("Souveniropolis");
     ////        $billto->setAddress("14 Main Street");
     ////        $billto->setCity("Pecan Springs");
     ////        $billto->setState("TX");
     ////        $billto->setZip("44628");
     ////        $billto->setCountry("USA");
     //        //create a transaction
     //        $transactionRequestType = new AnetAPI\TransactionRequestType();
     //        $transactionRequestType->setTransactionType("authCaptureTransaction");
     //        $transactionRequestType->setAmount(1.00);
     ////        $transactionRequestType->setPayment($paymentOne);
     ////        $transactionRequestType->setOrder($order);
     ////        $transactionRequestType->addToLineItems($lineitem);
     ////        $transactionRequestType->setTax($tax);
     ////        $transactionRequestType->setPoNumber($ponumber);
     ////        $transactionRequestType->setCustomer($customer);
     ////        $transactionRequestType->setBillTo($billto);
     ////        $transactionRequestType->setShipTo($shipto);
     //
     //        $request = new AnetAPI\CreateTransactionRequest();
     //        $request->setMerchantAuthentication($merchantAuthentication);
     //        $request->setRefId($refId);
     //        $request->setTransactionRequest($transactionRequestType);
     //        $controller = new AnetController\CreateTransactionController($request);
     //        $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); //Testing
     //       // $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION); // live
     //
     //        pr($response);
     //        exit;
     //
     //        $msg = '';
     //        if ($response != null) {
     //            $tresponse = $response->getTransactionResponse();
     //
     //            if (($tresponse != null) && ($tresponse->getResponseCode() == "1")) {
     //                $msg = "Transaction Successful ! : " . "<br/>";
     //                $msg .= "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "<br/>";
     //                $msg .= "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "<br/>";
     //            } else {
     //                $msg = "Charge Credit Card ERROR :  Invalid response\n";
     //            }
     //        } else {
     //            $msg = "Charge Credit card Null response returned";
     //        }
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     // $merchantAuthentication->setName("95x9PuD6b2"); // testing mode
     $merchantAuthentication->setName("42UHbr9Qa9B");
     // live mode
     //$merchantAuthentication->setTransactionKey("547z56Vcbs3Nz9R9");  // testing mode
     $merchantAuthentication->setTransactionKey("6468X36RkrKGm3k6");
     // live mode
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $this->loadModel('PaidCustomer');
     $this->loadModel('Transaction');
     $pcustomers = $this->PaidCustomer->find('all');
     //        pr($pcustomers);
     //        exit;
     $msg = '<ul>';
     foreach ($pcustomers as $pcustomer) {
         $pc = $pcustomer['PaidCustomer'];
         $creditCard->setCardNumber($pc['card_no']);
         // testing
         $creditCard->setExpirationDate($pc['exp_date']);
         // testing
         //     $creditCard->setCardNumber("4117733943147221"); // live
         //  $creditCard->setExpirationDate("07-2019"); //live
         $paymentOne = new AnetAPI\PaymentType();
         $paymentOne->setCreditCard($creditCard);
         $transactionData['paid_customer_id'] = $pc['id'];
         //    Bill To
         $billto = new AnetAPI\CustomerAddressType();
         $billto->setFirstName($pc['fname']);
         $billto->setLastName($pc['lname']);
         // $billto->setCompany("Souveniropolis");
         //$billto->setAddress("14 Main Street");
         //$billto->setCity("Pecan Springs");
         //$billto->setState("TX");
         $billto->setZip($pc['zip_code']);
         //$billto->setCountry("USA");
         // Create a transaction
         $transactionRequestType = new AnetAPI\TransactionRequestType();
         $transactionRequestType->setTransactionType("authCaptureTransaction");
         $transactionRequestType->setAmount($pc['amount']);
         $transactionRequestType->setPayment($paymentOne);
         $request = new AnetAPI\CreateTransactionRequest();
         $request->setMerchantAuthentication($merchantAuthentication);
         $request->setRefId($refId);
         $request->setTransactionRequest($transactionRequestType);
         $controller = new AnetController\CreateTransactionController($request);
         //   $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); //Testing
         $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
         // live
         //  pr($response); exit;
         $transactionData['error_msg'] = '';
         $transactionData['status'] = '';
         $transactionData['trx_id'] = '';
         $transactionData['auth_code'] = '';
         if ($response != null) {
             $tresponse = $response->getTransactionResponse();
             // pr($tresponse ); exit;
             if ($tresponse != null && $tresponse->getResponseCode() == "1") {
                 $transactionData['status'] = 'success';
                 $transactionData['trx_id'] = $tresponse->getTransId();
                 $transactionData['auth_code'] = $tresponse->getAuthCode();
                 $msg .= '<li> Transaction for ' . $pc['fname'] . ' ' . $pc['lname'] . ' successfull</li>';
             } else {
                 $transactionData['status'] = 'error';
                 $transactionData['error_msg'] = "Charge Credit Card ERROR :  Invalid response";
                 $msg .= '<li> Transaction for ' . $pc['fname'] . ' ' . $pc['lname'] . ' failed for Charge Credit Card ERROR</li>';
             }
         } else {
             $transactionData['status'] = 'error';
             $transactionData['error_msg'] = "Charge Credit card Null response returned";
             $msg .= '<li> Transaction for ' . $pc['fname'] . ' ' . $pc['lname'] . ' failed for Charge Credit card Null response</li>';
         }
         $this->Transaction->create();
         $this->Transaction->save($transactionData);
     }
     $msg .= '</ul>';
     $this->set(compact('msg'));
 }
<?php

require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common Set Up for API Credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("8V4xFm3z");
$merchantAuthentication->setTransactionKey("655AS4Ek7TJ42snq");
$request = new AnetAPI\UpdateSplitTenderGroupRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setSplitTenderId("116468");
$request->setSplitTenderStatus("voided");
$controller = new AnetController\UpdateSplitTenderGroupController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "SUCCESS : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
} else {
    echo "ERROR :  Invalid response\n";
    echo "Response Code : " . $response->getMessages()->getMessage()[0]->getCode() . " Resposne text: " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}
Exemplo n.º 17
0
 function createSubscription($post_order)
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($this->LOGIN_ID);
     $merchantAuthentication->setTransactionKey($this->TRANSACTION_KEY);
     $intervalLength = round($this->period / $post_order->payments_num);
     $refId = 'ref' . time();
     $start_date_h = date('Y-m-d', time());
     // first subscription payment today
     $total_occurences = $post_order->payments_num;
     $expiration = $post_order->cds_cc_year . "-" . $post_order->cd_cc_month;
     $names = explode("/", $post_order->cds_name);
     // Customer info
     $custID = round(time() / 3785);
     $customer = new AnetAPI\CustomerDataType();
     $customer->setId($custID);
     $customer->setEmail($post_order->cds_email);
     /*
     * 
      echo "<br>--------------------<br>";
      print_r($names);
      echo "<br>--------------------<br>";
     
      echo "First name: ".$firstname."<br>";
      echo "Last name: ".$lastname."<br>";
     * 
     */
     $firstname = $names[0];
     $lastname = $names[1];
     //$firstname = ($names[0] == '') ? "Loyal" : $names[0];
     //$lastname = ($names[2] == '') ? 'Client' : $names[2];
     // Subscription Type Info
     $subscription = new AnetAPI\ARBSubscriptionType();
     $subscription->setName("Subscription for {$post_order->item}");
     $interval = new AnetAPI\PaymentScheduleType\IntervalAType();
     $interval->setLength($intervalLength);
     $interval->setUnit("days");
     $paymentSchedule = new AnetAPI\PaymentScheduleType();
     $paymentSchedule->setInterval($interval);
     $paymentSchedule->setStartDate(new DateTime($start_date_h));
     $paymentSchedule->setTotalOccurrences($total_occurences);
     $paymentSchedule->setTrialOccurrences("1");
     $subscription->setPaymentSchedule($paymentSchedule);
     $subscription->setAmount($post_order->sum);
     $subscription->setTrialAmount("0.00");
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($post_order->cds_cc_number);
     $creditCard->setExpirationDate($expiration);
     $payment = new AnetAPI\PaymentType();
     $payment->setCreditCard($creditCard);
     $subscription->setPayment($payment);
     $billTo = new AnetAPI\NameAndAddressType();
     $billTo->setFirstName($firstname);
     $billTo->setLastName($lastname);
     $subscription->setBillTo($billTo);
     $request = new AnetAPI\ARBCreateSubscriptionRequest();
     $request->setmerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setSubscription($subscription);
     $controller = new AnetController\ARBCreateSubscriptionController($request);
     //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     /*
     * 
      echo "--------Subscription response <pre>";
      print_r($response);
      echo "<br>-------------------------<br>";
      die('Stopped ....');
     * 
     */
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         $msg = $response->getSubscriptionId();
         //echo "Message: ".$msg."<br>";
     } else {
         $this->save_log($response);
         $errorMessages = $response->getMessages()->getMessage();
         $msg = $errorMessages[0]->getCode() . "  " . $errorMessages[0]->getText();
     }
     // end else
     return $msg;
 }
<?php

require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials (with PayPal compatible merchant credentials)
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("5KP3u95bQpv");
$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S");
$payPalType = new AnetAPI\PayPalType();
$payPalType->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
$payPalType->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setPayPal($payPalType);
// Create an authorize and capture transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setAmount(151);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null) {
    $tresponse = $response->getTransactionResponse();
    if ($tresponse != null) {
        echo "Received response code: " . $tresponse->getResponseCode() . "\n";
        //Valid response codes: 1=Approved, 2=Declined, 3=Error, 5=Need Payer Consent
        echo "Secure acceptance URL: " . $tresponse->getSecureAcceptance()->getSecureAcceptanceUrl() . "\n";
Exemplo n.º 19
0
 public function individual_transaction($id = null)
 {
     $this->layout = 'ajax';
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName("95x9PuD6b2");
     // testing mode
     //$merchantAuthentication->setName("42UHbr9Qa9B"); // live mode
     $merchantAuthentication->setTransactionKey("547z56Vcbs3Nz9R9");
     // testing mode
     //$merchantAuthentication->setTransactionKey("6468X36RkrKGm3k6"); // live mode
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $this->loadModel('PaidCustomer');
     $this->loadModel('Transaction');
     $pcustomers = $this->PaidCustomer->find('first', array('conditions' => array('PaidCustomer.id' => $id)));
     //pr($pcustomers);
     //exit;
     $msg = '<ul>';
     //foreach ($pcustomers as $pcustomer):
     $pc = $pcustomers['PaidCustomer'];
     // pr($pc); exit;
     $creditCard->setCardNumber($pc['card_no']);
     // testing
     $creditCard->setExpirationDate($pc['exp_date']);
     // testing
     //     $creditCard->setCardNumber("4117733943147221"); // live
     //  $creditCard->setExpirationDate("07-2019"); //live
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     $transactionData['paid_customer_id'] = $pc['id'];
     //    Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($pc['fname']);
     $billto->setLastName($pc['lname']);
     // $billto->setCompany("Souveniropolis");
     //$billto->setAddress("14 Main Street");
     //$billto->setCity("Pecan Springs");
     //$billto->setState("TX");
     $billto->setZip($pc['zip_code']);
     //$billto->setCountry("USA");
     // Create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($pc['amount']);
     $transactionRequestType->setPayment($paymentOne);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     //Testing
     //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION); // live
     //  pr($response); exit;
     $transactionData['error_msg'] = '';
     $transactionData['status'] = '';
     $transactionData['trx_id'] = '';
     $transactionData['auth_code'] = '';
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         // pr($tresponse ); exit;
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             $transactionData['status'] = 'success';
             $transactionData['trx_id'] = $tresponse->getTransId();
             $transactionData['auth_code'] = $tresponse->getAuthCode();
             $msg .= '<li> Transaction for ' . $pc['fname'] . ' ' . $pc['lname'] . ' successfull</li>';
         } else {
             $transactionData['status'] = 'error';
             $transactionData['error_msg'] = "Charge Credit Card ERROR :  Invalid response";
             $msg .= '<li> Transaction for ' . $pc['fname'] . ' ' . $pc['lname'] . ' failed for Charge Credit Card ERROR</li>';
         }
     } else {
         $transactionData['status'] = 'error';
         $transactionData['error_msg'] = "Charge Credit card Null response returned";
         $msg .= '<li> Transaction for ' . $pc['fname'] . ' ' . $pc['lname'] . ' failed for Charge Credit card Null response</li>';
     }
     $this->Transaction->create();
     $this->Transaction->save($transactionData);
     // endforeach;
     //$msg .='</ul>';
     $msg1 = '<div class="alert alert-success">
     <button type="button" class="close" data-dismiss="alert">&times;</button>
     <strong>' . $msg . '</strong>
 </div>';
     $this->Session->setFlash($msg1);
     return $this->redirect($this->referer());
     //$this->set(compact('msg'));
 }
Exemplo n.º 20
0
 if ($cc_session_active === true) {
     // setting up variables
     $anet_sandbox_flag = get_server_value("anet_sandbox_flag") == 1 ? true : false;
     if ($anet_sandbox_flag === true) {
         $anet_api_login_id = get_server_value("anet_sandbox_api_login_id");
         $anet_transaction_key = get_server_value("anet_sandbox_transaction_key");
     } else {
         $anet_api_login_id = get_server_value("anet_live_api_login_id");
         $anet_transaction_key = get_server_value("anet_live_transaction_key");
     }
     $payment_amount = clean_input($_SESSION["Payment_Amount"]);
     //////////////////////// begin card charging process ////////////////////////////
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName("{$anet_api_login_id}");
     $merchantAuthentication->setTransactionKey("{$anet_transaction_key}");
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber("{$cc_info_array['number']}");
     $creditCard->setExpirationDate("{$cc_info_array['exp_yr']}-{$cc_info_array['exp_mo']}");
     //$creditCard->setCardCode("{$cc_info_array['cvv']}");
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName("{$cc_info_array['name_first']}");
     $billto->setLastName("{$cc_info_array['name_last']}");
     $billto->setAddress("{$cc_info_array['address1']} {$cc_info_array['address2']}");
     $billto->setCity("{$cc_info_array['city']}");
     $billto->setState("{$cc_info_array['state']}");
Exemplo n.º 21
0
 function authToken($customerId = null)
 {
     if (!isset($customerId)) {
         $customerId = $this->customerId();
     }
     $options = $this->options;
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($options['authname']);
     $merchantAuthentication->setTransactionKey($options['authkey']);
     $refId = 'ref' . time();
     $setting = new AnetAPI\SettingType();
     // 2do: fix domain name and path for iframe popup
     $setting->setSettingName("hostedProfileIFrameCommunicatorUrl");
     $setting->setSettingValue(Q_Html::themedUrl('plugins/Assets/authnet_iframe_communicator.html'));
     $setting->setSettingName("hostedProfilePageBorderVisible");
     $setting->setSettingValue("false");
     $frequest = new AnetAPI\GetHostedProfilePageRequest();
     $frequest->setMerchantAuthentication($merchantAuthentication);
     $frequest->setCustomerProfileId($customerId);
     $frequest->addToHostedProfileSettings($setting);
     $controller = new AnetController\GetHostedProfilePageController($frequest);
     $fresponse = $controller->executeWithApiResponse($options['server']);
     if (!isset($fresponse) or $fresponse->getMessages()->getResultCode() != "Ok") {
         $messages = $fresponse->getMessages()->getMessage();
         $message = reset($messages);
         throw new Assets_Exception_InvalidResponse(array('response' => $message->getCode() . ' ' . $message->getText()));
     }
     return $fresponse->getToken();
 }
Exemplo n.º 22
0
 function sandbox_authorize()
 {
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName('6cUTfQ5238');
     $merchantAuthentication->setTransactionKey('5bN8q5WT3qa257p9');
     return $merchantAuthentication;
 }