У меня есть две формы оплаты.Единый платеж и периодическое выставление счетов.До сих пор мне удавалось использовать пример кода, который Authorize.net предоставил для разового платежа, и сделал следующее.Я создал класс, и внутри этого класса создал функции с кодом, который они предоставили, и он работал.
Я собираюсь сделать то же самое с повторяющимся примером биллинга.Проблема в том, что я не уверен, какие части кода мне понадобятся для создания функции подписки.Функции кредитной карты, аутентификации и выставления счетов уже созданы.То, что я ищу, - это способ упорядочить параметры подписки, чтобы успешно создать их в моей песочнице.
Ниже я приведу пример кода, который предоставляет Authorize.net.
<?php
require 'vendor/autoload.php';
require_once 'constants/SampleCodeConstants.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
date_default_timezone_set('America/Los_Angeles');
define("AUTHORIZENET_LOG_FILE", "phplog");
function createSubscription($intervalLength)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
// Set the transaction's refId
$refId = 'ref' . time();
// Subscription Type Info
$subscription = new AnetAPI\ARBSubscriptionType();
$subscription->setName("Sample Subscription");
$interval = new AnetAPI\PaymentScheduleType\IntervalAType();
$interval->setLength($intervalLength);
$interval->setUnit("days");
$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(rand(1,99999)/12.0*12);
$subscription->setTrialAmount("0.00");
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2038-12");
$payment = new AnetAPI\PaymentType();
$payment->setCreditCard($creditCard);
$subscription->setPayment($payment);
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber("1234354");
$order->setDescription("Description of the subscription");
$subscription->setOrder($order);
$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";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
if(!defined('DONT_RUN_SAMPLES'))
createSubscription(23);
?>
Я ожидаю, что как только я заполню пробелы, составляющие мой индекс, я получу успешную подписку, которая не будет иметь пробного периода и будет выставлять счет клиенту один раз в месяц в течение следующих двенадцати месяцев.
ПРИМЕЧАНИЕ: я делаю это так, потому что это работало с разовым платежом.Если есть другой, более легкий путь, я весь в ушах.Спасибо.