如何从authorize.net中的现有customerprofileid获取customerpaymentrofileId我是autorize.net的新手。我需要获得客户的客户资料,以及我可以使用它们来为Authorize.net中的交易收取费用。
$email="soumik@esolzmail.com";
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("1212121");
$merchantAuthentication->setTransactionKey("12121221");
$refId = 'ref' . time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("2038-12");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
// Create the Bill To info
$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 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("Customer 2 Test PHP 1");
//$customerprofile->setMerchantCustomerId("M_".time());
$customerprofile->setEmail($email."d");
$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") )
{
echo "Succesfully create customer profile : " . $response->getCustomerProfileId() . "\n";
$paymentProfiles = $response->getCustomerPaymentProfileIdList();
echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n";
}
else
{
echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
//return $response;
echo "response=> <pre>"; print_r($response); echo "</pre>";
答案 0 :(得分:1)
您可以使用个人资料ID的GetCustomerProfile请求获取付款资料列表,该响应将包含付款资料列表。
对于php实现,您可以查看此PHP示例代码:https://github.com/AuthorizeNet/sample-code-php/blob/master/CustomerProfiles/get-customer-profile.php