如何通过Suitetalk添加CustomerCreditCardsList / CustomerCreditCards

时间:2019-04-03 01:13:15

标签: php netsuite suitetalk

我在沙盒中的Suitetalk遇到问题,在其中尝试用信用卡添加或更新客户记录的任何尝试均会成功,但不会在系统中创建卡。

尝试将现有的卡记录附加到帐户上也无效。

但是我可以更新现有卡,没问题。

有指针吗?

        $id,
        $ccNumber,
        $ccExpireDate,
        $ccName
    ) {
        $issuer = substr($ccNumber, 0, 1);
        $paymentMethod = 0;

        switch ($issuer) {
        case 3:
            $paymentMethod = PAYMENT_AMEX;
            break;
        case 4:
            $paymentMethod = PAYMENT_VISA;
            break;
        case 5:
            $paymentMethod = PAYMENT_MASTERCARD;
            break;
        case 6:
            $paymentMethod = PAYMENT_DISCOVER;
            break;
        default:
            throw new Exception("Invalid Credit Card Number provided.");
        }

        $customer = new Customer();
        $customer->internalId = $id;
        $customer->CreditCardsList = new CustomerCreditCardsList();
        $customer->CreditCardsList->creditCards = new CustomerCreditCards;

        $customer->CreditCardsList->creditCards->ccNumber = $ccNumber;
        $customer->CreditCardsList->creditCards->ccExpireDate = Carbon::create(
            $ccExpireDate
        )->toIso8601String();

        $customer->CreditCardsList->creditCards->ccName = $ccName;
        $customer->CreditCardsList->creditCards->validfrom = Carbon::now()
            ->subYear()
            ->toIso8601String();

        $customer->CreditCardsList->creditCards->paymentMethod = new RecordRef();
        $customer->CreditCardsList->creditCards->paymentMethod->internalId
            = $paymentMethod;

        $customer->CreditCardsList->creditCards->ccDefault = true;
        $customer->CreditCardsList->replaceAll = true;

        $paymentType = new SelectCustomFieldRef();
        $paymentType->value = new ListOrRecordRef();
        $paymentType->value->internalId = 5; // Direct Debit: 1, CC: 5
        $paymentType->scriptId = 'custentity_kl_member_member_payment_type';

        $customer->customFieldList = new CustomFieldList();
        $customer->customFieldList->customField = array($paymentType);

        $this->putData($id, "customer", $customer);
    }

    public function putData($id, string $type, $record)
    {
        $request = new UpdateRequest();
        $request->baseRef = new RecordRef();
        $request->baseRef->internalId = $id;
        $request->baseRef->type = $type;
        $request->record = $record;

        $updateResponse = $this->service->update($request);

        echo json_encode(
            $updateResponse,
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
        );

        if (!$updateResponse->writeResponse->status->isSuccess) {
            return false;
        } else {
            return true;
        }
    }

添加代码的工作原理基本上相同,只是附加了完整的客户记录。

这是记录内发送给SOAP的对象:

Array
(
    [0] => NetSuite\Classes\UpdateRequest Object
        (
            [record] => NetSuite\Classes\Customer Object
                (
                    [customFieldList] => NetSuite\Classes\CustomFieldList Object
                        (
                            [customField] => Array
                                (
                                    [0] => NetSuite\Classes\SelectCustomFieldRef Object
                                        (
                                            [value] => NetSuite\Classes\ListOrRecordRef Object
                                                (
                                                    [name] => 
                                                    [internalId] => 5
                                                    [externalId] => 
                                                    [typeId] => 
                                                )
                                            [internalId] => 
                                            [scriptId] => custentity_kl_member_member_payment_type
                                        )
                                )
                        )
                    [internalId] => 327516
                    [externalId] => 
                    [nullFieldList] => 
                    [CreditCardsList] => NetSuite\Classes\CustomerCreditCardsList Object
                        (
                            [creditCards] => NetSuite\Classes\CustomerCreditCards Object
                                (
                                    [internalId] => 
                                    [ccNumber] => 4012888888881881
                                    [ccExpireDate] => 2019-12-09T00:00:00+00:00
                                    [ccName] => Bill Gates
                                    [paymentMethod] => NetSuite\Classes\RecordRef Object
                                        (
                                            [internalId] => 5
                                            [externalId] => 
                                            [type] => 
                                            [name] => 
                                        )
                                    [cardState] => 
                                    [stateFrom] => 
                                    [debitcardIssueNo] => 
                                    [ccMemo] => 
                                    [validfrom] => 2018-04-03T07:01:58+00:00
                                    [ccDefault] => 1
                                )
                            [replaceAll] => 1
                        )
                )
            [baseRef] => NetSuite\Classes\RecordRef Object
                (
                    [internalId] => 327516
                    [externalId] => 
                    [type] => customer
                    [name] => 
                )
        )
)

但这是生成的SOAP:

<SOAP-ENV:Body>
    <ns3:update>
        <ns3:record internalId="327516" xsi:type="ns2:Customer">
            <ns2:customFieldList>
                <ns1:customField scriptId="custentity_kl_member_member_payment_type" xsi:type="ns1:SelectCustomFieldRef">
                    <ns1:value internalId="5" />
                </ns1:customField>
            </ns2:customFieldList>
        </ns3:record>
    </ns3:update>
</SOAP-ENV:Body>

2 个答案:

答案 0 :(得分:2)

问题是$customer->CreditCardsList应该是$customer->creditCardsList

我显然是个白痴。

答案 1 :(得分:0)

这是我用来更新客户ID:434,并添加新的信用卡记录的XML正文请求。

  <update xsi:type='platformMsgs:UpdateRequest'>
        <record xsi:type='listRel:Customer' internalId='434'>
            <creditCardsList replaceAll='false' xsi:type='listRel:CustomerCreditCardsList'>
                <creditCards xsi:type='listRel:CustomerCreditCards'>
                    <ccNumber xsi:type='xsd:string'>****************</ccNumber>
                    <ccExpireDate xsi:type='xsd:dateTime'>2021-04-03T05:54:29.245Z</ccExpireDate>
                    <paymentMethod xsi:type='platformCore:RecordRef' internalId='5'/>
                </creditCards>
            </creditCardsList>
        </record>
    </update>