Example #1
0
 public function createSubscription()
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $refId = $this->getPayload()->refId;
     // Subscription Type Info
     $subscription = new AnetAPI\ARBSubscriptionType();
     $subscription->setName($this->getPayload()->subscriptionName);
     $interval = new AnetAPI\PaymentScheduleType\IntervalAType();
     $interval->setLength($this->getPayload()->interval);
     $interval->setUnit($this->getPayload()->intervalType);
     $paymentSchedule = new AnetAPI\PaymentScheduleType();
     $paymentSchedule->setInterval($interval);
     $paymentSchedule->setStartDate(new \DateTime($this->getPayload()->startDate));
     $paymentSchedule->setTotalOccurrences("9999");
     /*$paymentSchedule->setTrialOccurrences("1");*/
     $subscription->setPaymentSchedule($paymentSchedule);
     $subscription->setAmount($this->getPayload()->price);
     /*$subscription->setTrialAmount("0.00");*/
     $profile = new AnetAPI\CustomerProfileIdType();
     $profile->setCustomerProfileId($this->getPayload()->customer['ID']);
     $profile->setCustomerPaymentProfileId($this->getPayload()->customer['PAYMENT_ID']);
     /*$profile->setCustomerAddressId($customerAddressId);*/
     $subscription->setProfile($profile);
     $request = new AnetAPI\ARBCreateSubscriptionRequest();
     $request->setmerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setSubscription($subscription);
     $controller = new AnetController\ARBCreateSubscriptionController($request);
     $this->setResponse($controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX));
     /*var_dump($this->getResponse());*/
     /*dd($response);*/
     if ($this->getResponse() != null && $this->getResponse()->getMessages()->getResultCode() == "Ok") {
         return $this->getResponse();
     } else {
         throw new PaymentErrorException($this->getResponse()->getMessages()->getMessage()[0]->getText());
     }
 }
Example #2
0
 function createSubscription($subs)
 {
     //$merchantAuthentication = $this->sandbox_authorize();
     $merchantAuthentication = $this->authorize();
     $amount = round($subs->amount / $subs->payments_num);
     $names = explode(" ", $subs->holder);
     // card holder name
     $firstname = $names[1];
     $lastname = $names[0];
     $exp_date = $subs->card_year . "-" . $subs->card_month;
     $period_sec = strtotime($subs->end) - strtotime($subs->start);
     //  Interval Length must be a value from 7 through 365 for day based subscriptions
     $intervalLength = round($period_sec / $subs->payments_num / 86400);
     $refId = 'ref' . time();
     // Subscription Type Info
     $subscription = new AnetAPI\ARBSubscriptionType();
     $subscription->setName($subs->coursename);
     $interval = new AnetAPI\PaymentScheduleType\IntervalAType();
     $interval->setLength($intervalLength);
     $interval->setUnit("days");
     $paymentSchedule = new AnetAPI\PaymentScheduleType();
     $paymentSchedule->setInterval($interval);
     $paymentSchedule->setStartDate(new DateTime($subs->start));
     $paymentSchedule->setTotalOccurrences($subs->payments_num);
     $subscription->setPaymentSchedule($paymentSchedule);
     $subscription->setAmount($amount);
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($subs->card_no);
     $creditCard->setExpirationDate($exp_date);
     $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::PRODUCTION);
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         return $response->getSubscriptionId();
     } else {
         $errorMessages = $response->getMessages()->getMessage();
         echo "Response : " . $errorMessages[0]->getCode() . "  " . $errorMessages[0]->getText() . "\n";
         return false;
     }
 }
$interval->setUnit("months");
$paymentSchedule = new AnetAPI\PaymentScheduleType();
$paymentSchedule->setInterval($interval);
$paymentSchedule->setStartDate(new DateTime('2020-08-30'));
$paymentSchedule->setTotalOccurrences("12");
$paymentSchedule->setTrialOccurrences("1");
$subscription->setPaymentSchedule($paymentSchedule);
$subscription->setAmount("10.29");
$subscription->setTrialAmount("0.00");
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2020-12");
$payment = new AnetAPI\PaymentType();
$payment->setCreditCard($creditCard);
$subscription->setPayment($payment);
$billTo = new AnetAPI\NameAndAddressType();
$billTo->setFirstName("John");
$billTo->setLastName("Smith");
$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);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n";
} else {
    echo "ERROR :  Invalid response\n";
    echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}
Example #4
0
 public function createSubscription(User $user)
 {
     // Common Set Up for API Credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $refId = $this->refId;
     // Subscription Type Info
     $subscription = new AnetAPI\ARBSubscriptionType();
     $subscription->setName($this->subscriptionName);
     $interval = new AnetAPI\PaymentScheduleType\IntervalAType();
     $interval->setLength($this->interval);
     $interval->setUnit($this->intervalType);
     $paymentSchedule = new AnetAPI\PaymentScheduleType();
     $paymentSchedule->setInterval($interval);
     $paymentSchedule->setStartDate(new \DateTime(date("Y-m-d")));
     $paymentSchedule->setTotalOccurrences("9999");
     /*$paymentSchedule->setTrialOccurrences("1");*/
     $subscription->setPaymentSchedule($paymentSchedule);
     $subscription->setAmount($this->price);
     /*$subscription->setTrialAmount("0.00");*/
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($this->cardNumber);
     $creditCard->setExpirationDate($this->expirationDate);
     $payment = new AnetAPI\PaymentType();
     $payment->setCreditCard($creditCard);
     $subscription->setPayment($payment);
     $billTo = new AnetAPI\NameAndAddressType();
     $billTo->setFirstName($user->first_name);
     $billTo->setLastName($user->last_name);
     $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);
     /*dd($response);*/
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         return $response->getSubscriptionId();
     } else {
         throw new PaymentErrorException($response->getMessages()->getMessage()[0]->getText());
     }
 }
Example #5
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;
 }