0

如何从 authorize.net 中的现有 customerprofileid 获取 customerpaymentrofileId 我是 autorize.net 的新手。我需要获取客户的 customerprofileid 的 customerpaymentrofileId ,以便我可以使用它们对 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>";
4

1 回答 1

1

您可以使用配置文件 ID 的GetCustomerProfile请求来获取付款配置文件列表,响应将包含付款配置文件列表。

对于 php 实现,您可以查看此 PHP 示例代码:https ://github.com/AuthorizeNet/sample-code-php/blob/master/CustomerProfiles/get-customer-profile.php

于 2016-09-09T06:13:07.937 回答