1

我已经创建了ARB subscription,但是为此我们需要传递客户信用卡信息及其到期日期,我们可以通过客户 ID 创建订阅吗?我们不想存储客户的任何卡信息,但我们有客户 ID,是否有可能或任何人有任何其他想法?任何帮助将不胜感激

<?php
error_reporting(E_ALL);
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('****');
    $merchantAuthentication->setTransactionKey('*****');

    // 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");

    /*echo "<pre>";
    print_r($creditCard);
    die;*/

    $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";
    }


    echo "<pre>";
    print_r($response);
    die;

    return $response;
}

if (!defined('DONT_RUN_SAMPLES'))
    createSubscription(23);
?>
4

1 回答 1

1

customerProfileId是的,只要您还拥有a,您就可以从 a 创建订阅customerPaymentProfileId

这是示例 XML:

<?xml version="1.0" encoding="utf-8"?>
<ARBCreateSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
    <merchantAuthentication>
        <name>API_USERNAME</name>
        <transactionKey>API_TRANSACTION_KEY</transactionKey>
    </merchantAuthentication>
    <refId>Sample</refId>
    <subscription>
        <name>Sample subscription</name>
        <paymentSchedule>
            <interval>
                <length>1</length>
                <unit>months</unit>
            </interval>
            <startDate>2020-08-30</startDate>
            <totalOccurrences>12</totalOccurrences>
            <trialOccurrences>1</trialOccurrences>
        </paymentSchedule>
        <amount>10.00</amount>
        <trialAmount>0.00</trialAmount>
        <profile>
            <customerProfileId>12345678</customerProfileId>
            <customerPaymentProfileId>987654342</customerPaymentProfileId>
        </profile>
    </subscription>
</ARBCreateSubscriptionRequest>

或者,如果您使用 JSON API:

{
    "ARBCreateSubscriptionRequest": {
        "merchantAuthentication": {
            "name": "API_USERNAME",
            "transactionKey": "API_TRANSACTION_KEY"
        },
        "refId": "123456",
        "subscription": {
            "name": "Sample subscription",
            "paymentSchedule": {
                "interval": {
                    "length": "1",
                    "unit": "months"
                },
                "startDate": "2020-08-30",
                "totalOccurrences": "12",
                "trialOccurrences": "1"
            },
            "amount": "10.29",
            "trialAmount": "0.00",
            "profile": {
                "customerProfileId": "12345678",
                "customerPaymentProfileId": "987654342"
            }
        }
    }
}

以下是使用他们的 SDK 的方法:

消除:

$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2038-12");

/*echo "<pre>";
print_r($creditCard);
die;*/

$payment = new AnetAPI\PaymentType();
$payment->setCreditCard($creditCard);
$subscription->setPayment($payment);    

和:

$billTo = new AnetAPI\NameAndAddressType();
$billTo->setFirstName("John");
$billTo->setLastName("Smith");

$subscription->setBillTo($billTo);

用。。。来代替:

$profile = new AnetAPI\CustomerProfileIdType();
$profile->setCustomerProfileId($customerProfileId);
$profile->setCustomerPaymentProfileId($customerPaymentProfileId);
$subscription->setProfile($profile);    
于 2019-09-16T11:59:04.123 回答