AuthorizeNet / sample-code-php

This repository contains working code samples which demonstrate php integration with the Authorize.Net API
MIT License
177 stars 197 forks source link

How to properly save customer information with their subscription? #80

Closed globatum closed 7 years ago

globatum commented 7 years ago

I have looked around and tried a few solutions online, but I keep running into method does not exist errors or the data is simply not being saved.

Customer ID:
Name: Markus-Allen Proctor Company:
Address: 1111 Werkin App St. City: Baltimore State/Province: MD Zip/Postal Code: 20774 Country:
Phone:
Fax:
Email:

The fields I care about never show any information (when logging into auth.net to view subs)

`$paymentSchedule = new AnetAPI\PaymentScheduleType(); $paymentSchedule->setInterval($interval); $paymentSchedule->setStartDate(new DateTime($date)); $paymentSchedule->setTotalOccurrences(12); $subscription->setPaymentSchedule($paymentSchedule); $subscription->setAmount($a); $subscription->billToAddress = $address; $subscription->billToCity = $city; $subscription->billToState = $state; $subscription->billToZip = $zip; $subscription->customerEmail = $user->email; $subscription->customerPhoneNumber = $user->phone;

    $creditCard = new AnetAPI\CreditCardType();
    $creditCard->setCardNumber($cardnum);
    $creditCard->setExpirationDate("20" . $yy . "-" . $mm);
    $creditCard->setCardCode($cvc);

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

    $paymentprofile = new AnetAPI\CustomerPaymentProfileType();
    $paymentprofile->setCustomerType('individual');
    $paymentprofile->setPayment($payment);
    $customerprofile = new AnetAPI\CustomerProfileType();
    $customerprofile->setEmail($user->email);

    $billTo = new AnetAPI\NameAndAddressType();
    $billTo->setFirstName($fName);
    $billTo->setLastName($lName);
    $billTo->setAddress("$address");
    $billTo->setCity($city);
    $billTo->setState($state);
    $billTo->setZip($zip);
    $subscription->setBillTo($billTo);

    $request = new AnetAPI\ARBCreateSubscriptionRequest();
    $request->setmerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setSubscription($subscription);
    $controller = new AnetController\ARBCreateSubscriptionController($request);`

In short, how do I save the customer's contact info so that it shows up in the authnet console?

adavidw commented 7 years ago

Have you tried adding a line like $request->setProfile($customerprofile); ?

adavidw commented 7 years ago

Or, maybe try this:

$customer = new AnetAPI\CustomerType();
$customer->setEmail($user->email);
$customer->setPhoneNumber($user->phone);
$request->setCustomer($customer);

I'm on a plane and can't really test it myself right now, but please let me know if I'm on the right track here.

globatum commented 7 years ago

@adavidw

This error pops up

FatalThrowableError in Billing.php line 104:
Call to undefined method net\authorize\api\contract\v1\ARBCreateSubscriptionRequest::setCustomer()
globatum commented 7 years ago

I have the solution.

$customer = new AnetAPI\CustomerType();
$customer->setEmail($user->email);
$customer->setPhoneNumber($user->phone);
$subscription->setCustomer($customer);

setCustomer is not a method in `ARBCreateSubscriptionRequest()`
globatum commented 7 years ago

I have the solution.

$customer = new AnetAPI\CustomerType();
$customer->setEmail($user->email);
$customer->setPhoneNumber($user->phone);
$subscription->setCustomer($customer);

setCustomer is not a method in ARBCreateSubscriptionRequest()