Reputation: 159
I'm building a front-end for NS that sits outside the Webstore. Our payment gateway has a web app which is capable of creating a ref number and auth code, these need to be appended to the salesorder so the payment provider can process the payment when the order has been dispatched. Is this possible or am I barking up the wrong tree?
I'm pretty new to NS, apologies if the answer is an obvious one!
The error message I'm getting is:
Code: INVALID_RCRD_TRANSFRM Details: That type of record transformation is not allowed. Please see the documentation for a list of supported transformation types.
and here is the code I'm trying to use in my RESTlet:
function authorizeCreditCard(dataIn) {
nlapiLogExecution('DEBUG', 'Pre Transform', JSON.stringify(dataIn));
var customerpayment, paymentrecord
try {
customerpayment = nlapiTransformRecord('salesorder', dataIn.id, 'customerpayment', {
"memo": dataIn.memo,
"authCode": dataIn.authCode,
"pnRefNum": dataIn.pnRefNum,
"ccApproved": dataIn.ccApproved,
"ccAvsStreetMatch": dataIn.ccAvsStreetMatch,
"ccAvsZipMatch": dataIn.ccAvsZipMatch,
"ccSecurityCodeMatch": dataIn.ccSecurityCodeMatch
});
paymentrecord = nlapiSubmitRecord(customerpayment);
} catch (e) {
nlapiLogExecution('ERROR', 'Transform failed', e);
}
nlapiLogExecution('DEBUG', 'Post Transform: CP', JSON.stringify(customerpayment));
nlapiLogExecution('DEBUG', 'Post Transform: PR', JSON.stringify(paymentrecord));
if (paymentrecord) {
return {
status: 'success',
data: paymentrecord
}
}
return {
status: 'error',
message: 'something went wrong'
}
}
Upvotes: 0
Views: 1660
Reputation: 159
@bknights @pedro-bustos Thanks both for your help.
I have figured it out! Largely due to your answer bknights.
You can only add an authcode etc when you first create a salesorder. This means I have to slightly refactor things but I can now add auth codes and pn refs.
Upvotes: 0
Reputation: 15462
In order to do authorization in an external system and settlement/capture automatically in Netsuite the first step is having the same payment processor (or apparently just the same merchant bank but YMMMV) for the external system's authorization.
The the following snippets work to create a sales order that has the authorization. Later when you fulfill the order the resulting cash sale will trigger settlement and capture. If you can't configure the same processor in NS as was used for the authorization most merchant banks use a really simple to set up API.
function dummyExpDate() {
var d = new Date();
return ('0' + (d.getMonth() + 1)).slice(-2) + '/' + (d.getFullYear() + 1); // some future date
}
var soRec = nlapiTransformRecord('customer', custId, 'salesorder, {recordmode: 'dynamic'});
soRec.setFieldValue('paymentmethod', 'somepaymentmethodid_Visa_works'); // some payment method id for NS happiness
soRec.setFieldValue('ccnumber', '4111111111111111'); // dummy valid visa for NS happiness
soRec.setFieldValue('ccexpiredate', dummyExpDate());
soRec.setFieldValue('pnrefnum', pnref);
soRec.setFieldValue('ccapproved', 'T');
Upvotes: 0
Reputation: 74
It is not possible to transform a salerorder into customerpayment. A salerorder can only transform into cashsale, invoice, itemfulfillment, returnauthorization and revenuecommitment. I think you should first convert your salerorder into an invoice and then make the payment of the customer with customerpayment.
regards
Upvotes: 1