Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing correct customer data to Sage Pay #29

Closed
losttheplot opened this issue Nov 4, 2014 · 9 comments
Closed

Passing correct customer data to Sage Pay #29

losttheplot opened this issue Nov 4, 2014 · 9 comments

Comments

@losttheplot
Copy link

HI. Thanks ever so much for publishing this project, which looks like it's going to save me a stack of work :)

I'm having a problem loading the correct customer details and am wondering what I'm doing wrong. My code is as follows:

// set the billing details
$billing_addr = new Academe\SagePay\Model\Address();
$billing_addr->setField('Surname', $data['c_surname']);
$billing_addr->setField('Firstnames', $data['c_firstname']);
$billing_addr->setField('Address1', $data['c_add1']);
$billing_addr->setField('Address2', $data['c_add2']);
$billing_addr->setField('City', $data['c_town']);
$billing_addr->setField('PostCode', $data['c_postcode']);
$billing_addr->setField('Country', 'GB');
$server->setBillingAddress($billing_addr);
// set the delivery details
$delivery_addr = new Academe\SagePay\Model\Address();
$delivery_addr->setField('Surname', $data['c_surname']);
$delivery_addr->setField('Firstnames', $data['c_firstname']);
$delivery_addr->setField('Address1', $data['c_add1']);
$delivery_addr->setField('Address2', $data['c_add2']);
$delivery_addr->setField('City', $data['c_town']);
$delivery_addr->setField('PostCode', $data['c_postcode']);
$delivery_addr->setField('Country', 'GB');
$server->setDeliveryAddress($delivery_addr);
// set the customer details
$customer_details = new Academe\SagePay\Model\Customer();
$customer_details->setField('CustomerEMail', $data['email']);
$server->setCustomerModel($customer_details);
// generate a unique VendorTxCode to identify the transaction
$server->save();

Both the local storage db and SagePay's systems record both the billing and delivery addresses with the data entered above for 'billing', and the email address is not recorded at all. If you have time, please could you explain what I'm doing wrong?

@judgej
Copy link
Member

judgej commented Nov 4, 2014

If the billing and shipping address are the same, then you could pass the same address in twice - no need to create separate models if they are identical. I haven't looked at the code to remind me, but I'm sure if you set just the billing or shipping address, then the other one will automatically be set to be the same.

The emails are set on the addresses, since SagePay will accept both a shipping email and a billing email. $billing_addr->setField('Email', $data['email']); should do it.

Was it just the email that was the problem, or am I missing something else?

@losttheplot
Copy link
Author

Thanks. I thought I'd tried unsuccessfully to pass the email address as you explained - I will try again.

With the addresses, I get that they can be the same but in this instance I need to store two different sets of contact details as the customer is sometimes a child and the card-payer is often a parent. The records need to show that distinction.

@judgej
Copy link
Member

judgej commented Nov 4, 2014

I just took your example code as production code, so my bad for assuming :-)

Best of luck. I'm going to come back to finishing off this module properly before the end of the year - there are a number of lose ends and not enough tests. If you find any holes in the functionality or any improvements that you think may help, then feel free to raise them as issues and it will go on the list. Would be nice (before the end of the year too) to write a connection for Omnipay, so this package can be used as an Omnipay driver, as well as standalone.

@losttheplot
Copy link
Author

I'm an OOP novice but I will try and work out what is going on - or not. Would I be correct in assuming that in your current production use, you are always using the same address for billing and delivery, and are not passing the email address?

@consilience
Copy link

Hmm, I might be wrong there. Try $server->setField('CustomerEMail', $data['email']); rather than on the $customer_details.

I'll need to go through the SagePay documentation again. It changes quite a log between point releases (several times a year) from protocol V3. The customer details, the shipping details and the billing details can all refer to completely different people.

(posted by @judgej)

@losttheplot
Copy link
Author

Brilliant, thanks - that works a treat for all the fields :)

I didn't realise one could set a field so simply...

$server->setField('BillingSurname', $data['c_surname']); // 20 chars
$server->setField('BillingFirstnames', $data['c_firstname']); // 20 chars
$server->setField('BillingAddress1', $data['c_add1']); // 100 chars
$server->setField('BillingAddress2', $data['c_add2']); // 100 chars
$server->setField('BillingCity', $data['c_town']); // 40 chars
$server->setField('BillingPostCode', $data['c_postcode']); // 10 chars
$server->setField('BillingCountry', 'GB'); //2 chars, ISO 3166 e.g. GB, DE
$server->setField('CustomerEMail', $data['email']); // 255 chars
$server->setField('DeliverySurname', $data['surname']); // 20 chars
$server->setField('DeliveryFirstnames', $data['firstname']); // 20 chars
$server->setField('DeliveryAddress1', $data['add1']); // 100 chars
$server->setField('DeliveryAddress2', $data['add2']); // 100 chars
$server->setField('DeliveryCity', $data['town']); // 40 chars
$server->setField('DeliveryPostCode', $data['postcode']); // 10 chars
$server->setField('DeliveryCountry', 'GB'); //2 chars, ISO 3166 e.g. GB, DE

@judgej
Copy link
Member

judgej commented Nov 4, 2014

Ideally you whould be able to do $server->CustomerEMail = $data['email'] but I've not put the magic methods in for that yet.

SagePay takes all the fields in one big, flat, list. The classes such as the Address and Customer are just there for convenience, as a way of grouping fields together in your code and abstracting them slightly from the fields that SagePay names, and adding some validation and a way to transform some of the fields (e.g. a basket is turned into XML or CSV data). But if you want to use the raw SagePay fields, then set them all manually as you have done above, and it should work fine.

@losttheplot
Copy link
Author

Thanks. What you're doing is great, but for now, with my current project, the simple approach works well :)

@judgej
Copy link
Member

judgej commented Nov 4, 2014

Cool. I'll close this ticket. Please re-open if still not working, or raise another ticket if there are further issues.

@judgej judgej closed this as completed Nov 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants