在authorize.net中创建客户付款资料

时间:2018-04-02 15:32:21

标签: authorize.net authorize.net-cim

我在使用API​​创建客户档案时面临一种非常奇怪的行为。虽然我已经彻底阅读了文档,但没有成功。

我首先创建customer profile时没有配置文件和payment profile,但下次用户返回并添加payment profile时(因为客户配置文件已存在)我只使用createCustomerPaymentProfile。问题是,在第一步中我不包括$billto->setZip("44628");,并且进展顺利。但是,当我只制作payment Profile时,它要求我将zip code包含在其他明智的地方,它会给出错误

  

“有一个或多个缺少或无效的必填字段。”

我使用与文档的php部分完全相同的代码只是文本/参数的更改。

create customer profile

create customer payment profile

制作客户资料:

private function createCustomerProfile($data)
    {
        /* Create a merchantAuthenticationType object with authentication details
           retrieved from the constants file */
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication->setName("auth");
        $merchantAuthentication->setTransactionKey("transkey");

        // Set the transaction's refId
        $refId = 'ref' . time();

        $paymentProfile=$this->newPaymentProfile($data);
        // Create a new CustomerProfileType and add the payment profile object
        $customerProfile = new AnetAPI\CustomerProfileType();
        $customerProfile->setDescription("Customer 2 Test PHP");
        $customerProfile->setMerchantCustomerId($name. time());
        $customerProfile->setEmail($email);
        $customerProfile->setpaymentProfiles($paymentProfile);

        // Assemble the complete transaction request
        $request = new AnetAPI\CreateCustomerProfileRequest();
        $request->setMerchantAuthentication($merchantAuthentication);
        $request->setRefId($refId);
        $request->setProfile($customerProfile);

        // Create the controller and get the response
        $controller = new AnetController\CreateCustomerProfileController($request);
        $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);


        if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
            $paymentProfiles = $response->getCustomerPaymentProfileIdList();

            //Insert into database for the profile and payment profile update
        } else {
            echo "ERROR :  Invalid response\n";
            $errorMessages = $response->getMessages()->getMessage();
            echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
        }
        return $response;

制作客户付款资料

private function createCustomerPaymentProfile($data){

    /* Create a merchantAuthenticationType object with authentication details
  retrieved from the constants file */
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName("name");
    $merchantAuthentication->setTransactionKey("transkey");

    // Set the transaction's refId
    $refId = 'ref' . time();

    $paymentProfile=$this->newPaymentProfile($data);


    // Assemble the complete transaction request
    $paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
    $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);

    // Add an existing profile id to the request
    $paymentprofilerequest->setCustomerProfileId($data['profile_id']);
    $paymentprofilerequest->setPaymentProfile($paymentProfile[0]);
    $paymentprofilerequest->setValidationMode("liveMode");

    // Create the controller and get the response
    $controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

    if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
        echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";

        //Insert into database for the profile and payment profile update
    } else {
        echo "Create Customer Payment Profile: ERROR Invalid response\n";
        $errorMessages = $response->getMessages()->getMessage();
        echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";

    }
    return $response;
}

为了重新使用目的,我已经制作了一个返回付款资料数组

的常见付款资料
private function newPaymentProfile($data){
        // Set credit card information for payment profile
        $creditCard = new AnetAPI\CreditCardType();
        $creditCard->setCardNumber($data['account_number']);
        $creditCard->setExpirationDate($data['date']);
        $creditCard->setCardCode($data['securiy_no']);
        $paymentCreditCard = new AnetAPI\PaymentType();
        $paymentCreditCard->setCreditCard($creditCard);

        // Create the Bill To info for new payment type
        $billTo = new AnetAPI\CustomerAddressType();
        $billTo->setFirstName($data['holder_name']);
        $billTo->setAddress($data['billing_address']);
        $billTo->setPhoneNumber($data['phone']);
        $billTo->setfaxNumber($data['fax']);


        // Create a new CustomerPaymentProfile object
        $paymentProfile = new AnetAPI\CustomerPaymentProfileType();
        $paymentProfile->setCustomerType('individual');
        $paymentProfile->setBillTo($billTo);
        $paymentProfile->setPayment($paymentCreditCard);
        $paymentProfiles[]=$paymentProfile;
        return $paymentProfiles;
    }

0 个答案:

没有答案