目录

Creating a Loyalty Card Model

Function

Adds a loyalty card model to the Huawei server.

Scenario

This API is used to add a loyalty card model, for example, the Gold card of a club, to the Huawei server.

Restrictions

You need to create an app in AppGallery Connect and apply for services corresponding to the passes.

Prototype

Protocol

HTTPS POST

Direction

Developer server -> Huawei server

URL

{url}/hmspass/v1/loyalty/model

Set the {url} variable based on the region where the server is located. For details, please refer to Wallet Server Addresses.

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Request Parameters

Request Header

Parameter

Mandatory/Optional

Type

Description

Authorization

Mandatory

String

Authorization code. For details about how to obtain the value, please refer to the Client Credentials mode in OAuth 2.0-based Authentication. In this mode, client_id and client_secret are respectively the App ID and App key of the app that you created in AppGallery Connect. Concatenate the value of access_token to the end of Bearer, with a space in between, to generate the value of Authorization.

Content-Type

Mandatory

String

The value is always application/json;charset=utf-8.

Accept

Mandatory

String

The value is always application/json;charset=utf-8.

Request Body

Parameter

Mandatory/Optional

Type

Description

For details, please refer to the HwWalletObject Parameters.

Mandatory

HwWalletObject

Pass model to be added.

Request Example

POST /hmspass/v1/loyalty/model HTTP/1.1
Content-Type: application/json;charset=utf-8
Authorization: Bearer ***
Host: wallet-passentrust-drcn.cloud.huawei.com.cn
Accept: application/json;charset=utf-8
{
  "passVersion": "1.0",
  "passTypeIdentifier": "hwpass.com.huawei.wallet.loyalty.test",
  "passStyleIdentifier": "loyaltyModelTest",
  "organizationName": "Huawei",
  "fields": {
    "countryCode": "CN",
    "locationList": [
      {
        "longitude": "114.0679603815",
        "latitude": "22.6592051284"
      }
    ],
    "commonFields": [
      {
        "key": "logo",
        "value": "https://www.huawei.com/XXX.png",
        "label": "Logo"
      },
      {
        "key": "backgroundImage",
        "value": "https://www.huawei.com/XXX.png",
        "label": "Background"
      },
      {
        "key": "name",
        "value": "XXX Gold Loyalty Card",
        "localizedValue": "cardName"
      },
      {
        "key": "merchantName",
        "value": "XXX Super Market",
         "localizedValue": "merchantNameI18N"
      }
    ],
    "appendFields": [
      {
        "key": "backgroundColor",
        "value": "#483d8b",
        "label": "Background Color"
      },
      {
        "key": "hotline",
        "value": "8006011450",
        "label": "Hotline"
      },
      {
        "key": "website",
        "value": "https://www.huawei.com",
        "label": "Website"
      },
      {
        "key": "level",
        "value": "Gold",
        "label": "Membership Tier"
      }
    ],
    "messageList": [
      {
        "key": "message[0]",
        "value": "Best wishes.",
        "label": "Message"
      }
    ],
    "imageList": [
      {
        "key": "mainImage[0]",
        "value": "https://www.huawei.com/XXX0.png"
      },
      {
        "key": "mainImage[1]",
        "value": "https://www.huawei.com/XXX1.png"
      },
      {
        "key": "mainImage[2]",
        "value": "https://www.huawei.com/XXX2.png"
      }
    ],
    "localized": [
      {
        "key": "cardName",
        "language": "zh-cn",
        "value": "XXX Gold Loyalty Card"
      },
      {
        "key": "cardName",
        "language": "en",
        "value": "XXX Gold Loyalty Card"
      },
      {
        "key": "merchantNameI18N",
        "language": "zh-cn",
        "value": "XXX Super Market"
      },
      {
        "key": "merchantNameI18N",
        "language": "en",
        "value": "XXX Super Market"
      }
    ]
  }
}

Response Parameters

When the result code is 200:

Parameter

Type

Description

For details, please refer to the HwWalletObject Parameters.

HwWalletObject

Added pass model.

Response Example

HTTP/1.1 200 OK
Content-Type: application/json
{
  "passVersion": "1.0",
  "passTypeIdentifier": "hwpass.com.huawei.wallet.loyalty.test",
  "passStyleIdentifier": "loyaltyModelTest",
  "organizationName": "Huawei",
  "fields": {
    "countryCode": "CN",
    "locationList": [
      {
        "longitude": "114.0679603815",
        "latitude": "22.6592051284"
      }
    ],
    "commonFields": [
      {
        "key": "logo",
        "value": "https://www.huawei.com/XXX.png",
        "label": "Logo"
      },
      {
        "key": "backgroundImage",
        "value": "https://www.huawei.com/XXX.png",
        "label": "Background"
      },
      {
        "key": "name",
        "value": "XXX Gold Loyalty Card",
        "localizedValue": "cardName"
      },
      {
        "key": "merchantName",
        "value": "XXX Super Market",
        "localizedValue": "merchantNameI18N"
      }
    ],
    "appendFields": [
      {
        "key": "backgroundColor",
        "value": "#483d8b",
        "label": "Background Color"
      },
      {
        "key": "hotline",
        "value": "8006011450",
        "label": "Hotline"
      },
      {
        "key": "website",
        "value": "https://www.huawei.com",
        "label": "Website"
      },
      {
        "key": "level",
        "value": "Gold",
        "label": "Membership Tier"
      }
    ],
    "messageList": [
      {
        "key": "message[0]",
        "value": "Best wishes.",
        "label": "Message"
      }
    ],
    "imageList": [
      {
        "key": "mainImage[0]",
        "value": "https://www.huawei.com/XXX0.png"
      },
      {
        "key": "mainImage[1]",
        "value": "https://www.huawei.com/XXX1.png"
      },
      {
        "key": "mainImage[2]",
        "value": "https://www.huawei.com/XXX2.png"
      }
    ],
    "localized": [
      {
        "key": "cardName",
        "language": "zh-cn",
        "value": "XXX Gold Loyalty Card"
      },
      {
        "key": "cardName",
        "language": "en",
        "value": "XXX Gold Loyalty Card"
      },
      {
        "key": "merchantNameI18N",
        "language": "zh-cn",
        "value": "XXX Super Market"
      },
      {
        "key": "merchantNameI18N",
        "language": "en",
        "value": "XXX Super Market"
      }
    ]
  }
}

Result Codes

For details, please refer to Result Codes.

Call Example

public HwWalletObject postHwWalletObjectToWalletServer(String url, HwWalletObject hwWalletObject) {
    // Construct the HTTP header.
    HttpHeaders header = constructHttpHeaders();
    // Construct the HTTP body.
    String body = CommonUtil.toJson(hwWalletObject);
    JSONObject jsonObj = JSONObject.parseObject(body);
    System.out.println("Request JSON : " + jsonObj);
    // Construct the HTTP URL.
    String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl");
    String walletServerUrl = baseUrl + url;

    // Send the HTTP request and obtain the response.
    HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObj, header);
    ResponseEntity<HwWalletObject> exchange =
        REST_TEMPLATE.exchange(walletServerUrl, HttpMethod.POST, entity, HwWalletObject.class);

    // Return the pushed wallet model.
    return exchange.getBody();
}