この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

AuthorizationRequest クラス

サービスコール中に承認要求に関する情報をゲートウェイアダプターに送信します。

名前空間

CommercePayments

使用方法

このクラスには、トランザクション承認要求に関する情報が含まれます。ゲートウェイアダプターは、承認 JSON 要求を作成するときにこのクラスから項目を読み取り、支払ゲートウェイに送信します。このクラスのオブジェクトは、PaymentGatewayContext クラスgetPaymentRequest() をコールすることで使用できます。

承認要求に関する情報を保存する buildAuthRequest クラスの作成。

1private String buildAuthRequest(commercepayments.AuthorizationRequest authRequest) {
2        // Multiply amount by 100.0 to convert to cents
3        String requestBody = createRequestBody(String.ValueOf((authRequest.amount*100.0).intValue()), authRequest);
4        return requestBody;
5
6        private String createRequestBody(String amount, commercepayments.AuthorizationRequest authRequest) {
7        JSONGenerator jsonGeneratorInstance = JSON.createGenerator(true);
8        String currencyIso = authRequest.currencyIsoCode;
9        commercepayments.AuthApiPaymentMethodRequest paymentMethod = authRequest.paymentMethod;
10        commercepayments.GatewayErrorResponse error;
11        // Write data to the JSON string.
12        jsonGeneratorInstance.writeStartObject();
13        jsonGeneratorInstance.writeStringField('merchantAccount', '{!$Credential.Username}');
14        jsonGeneratorInstance.writeStringField('reference', authRequest.comments == null ? 'randomstring' : authRequest.comments);
15
16        if(currencyIso == null) {
17            currencyIso = UserInfo.getDefaultCurrency();
18        }
19
20        jsonGeneratorInstance.writeFieldName('amount');
21        jsonGeneratorInstance.writeStartObject();
22        jsonGeneratorInstance.writeStringField('value', amount);
23        jsonGeneratorInstance.writeStringField('currency', currencyIso);
24        jsonGeneratorInstance.writeEndObject();
25
26        commercepayments.CardPaymentMethodRequest cardPaymentMethod;
27        if(paymentMethod != null) {
28            cardPaymentMethod = paymentMethod.cardPaymentMethod;
29            if (cardPaymentMethod != null) {
30                if (cardPaymentMethod.CardCategory != null) {
31                    if (commercepayments.CardCategory.CreditCard == cardPaymentMethod.CardCategory) {
32                        jsonGeneratorInstance.writeFieldName('card');
33                        jsonGeneratorInstance.writeStartObject();
34                        if (cardPaymentMethod.cvv != null)
35                            jsonGeneratorInstance.writeStringField('cvc', String.ValueOf(cardPaymentMethod.cvv));
36                        if (cardPaymentMethod.cardholdername != null)
37                            jsonGeneratorInstance.writeStringField('holderName', cardPaymentMethod.cardholdername);
38                        if (cardPaymentMethod.cardnumber != null)
39                            jsonGeneratorInstance.writeStringField('number', cardPaymentMethod.cardnumber);
40                        if (cardPaymentMethod.expiryMonth != null && cardPaymentMethod.expiryYear != null ) {
41                            String expMonth = ((String.ValueOf(cardPaymentMethod.expiryMonth)).length() == 1 ? '0' : '') + String.ValueOf(cardPaymentMethod.expiryMonth);
42                            jsonGeneratorInstance.writeStringField('expiryMonth', expMonth);
43                            jsonGeneratorInstance.writeStringField('expiryYear', String.ValueOf(cardPaymentMethod.expiryYear));
44                        }
45                        jsonGeneratorInstance.writeEndObject();
46                    } else {
47                    //Support for other card type
48                    }
49                } else {
50                    throw new SampleValidationException('Required Field Missing : CardCategory');
51                }
52            } else {
53                throw new SampleValidationException('Required Field Missing : CardPaymentMethod');
54            }
55        } else {
56            throw new SampleValidationException('Required Field Missing : PaymentMethod');
57        }
58        jsonGeneratorInstance.writeEndObject();
59        return jsonGeneratorInstance.getAsString();
60    }

AuthorizationRequest のコンストラクター

AuthorizationRequest のコンストラクターは次のとおりです。

AuthorizationRequest(amount)

承認要求の金額を作成するためのコンストラクター。このコンストラクターはテストでの使用を目的としており、Apex テストコンテキスト外で使用された場合は例外が発生します。

署名

global AuthorizationRequest(Double amount)

パラメーター

amount
型: Double
承認の金額。

AuthorizationRequest のプロパティ

AuthorizationRequest のプロパティは次のとおりです。

accountId

承認が実行される顧客取引先。

署名

global String accountId {get; set;}

プロパティ値

型: String

amount

承認の総額。正または負の値になります。

署名

global Double amount {get; set;}

プロパティ値

型: Double

comments

承認に関するコメント。ユーザーは、コメントを入力して追加情報を提供できます。

署名

global String comments {get; set;}

プロパティ値

型: String

currencyIsoCode

承認要求の ISO 通貨コード。

署名

global String currencyIsoCode {get; set;}

プロパティ値

型: String

paymentMethod

承認要求で承認を処理するために使用される支払方法。

署名

global AuthApiPaymentMethodRequest paymentMethod {get; set;}

プロパティ値

型: AuthApiPaymentMethodRequest

AuthorizationRequest のメソッド

AuthorizationRequest のメソッドは次のとおりです。

equals(obj)

リスト内の外部オブジェクトの同等性を判断して、AuthorizationRequest 型のリストの整合性を維持します。このメソッドは動的で、Java の equals メソッドに基づきます。

署名

global Boolean equals(Object obj)

パラメーター

obj
型: Object
キーが検証される外部オブジェクト。

戻り値

型: Boolean

hashCode()

リスト内の外部オブジェクトの一意性を判断して、AuthorizationRequest 型のリストの整合性を維持します。

署名

global Integer hashCode()

戻り値

型: Integer

toString()

日付を文字列に変換します。

署名

global String toString()

戻り値

型: String