다음 패스 카테고리 중 하나를 선택하여 사용 방법을 자세히 알아보세요.
이 섹션에는 쿠폰의 코드 스니펫이 포함되어 있습니다. 다음 클래스와 객체가 나와 있습니다.
JSON OfferClass
OfferClass
를 정의한 후 다음 REST URI에 대해 POST
요청을 실행하여 해당 클래스를 삽입합니다.
https://walletobjects.googleapis.com/walletobjects/v1/offerClass
엄격한 오류 파싱을 설정하고 중복 ID 필드와 같은 더 많은 오류를 포착하려면 REST URI에 strict=true
매개변수를 추가합니다.
https://walletobjects.googleapis.com/walletobjects/v1/offerClass?strict=true
다음은 OfferClass
를 나타내는 JSON 리소스를 보여주는 예시입니다. JSON은 POST
요청의 본문으로 보내야 합니다. 다음 코드 샘플은 OfferClass
를 정의하고 삽입하는 구체적인 방법을 보여줍니다.
리소스
{ "kind": "walletobjects#offerClass", "id": "#{issuerId}.#{classId}", "issuerName": "Baconrista Coffee", "title": "20% off on one bacon fat latte", "redemptionChannel": "both", "provider": "Baconrista Deals", "titleImage": { "kind": "walletobjects#image", "sourceUri": { "kind": "walletobjects#uri", "uri": "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg" } }, "locations": [{ "kind": "walletobjects#latLongPoint", "latitude": 37.424015499999996, "longitude": -122.09259560000001 },{ "kind": "walletobjects#latLongPoint", "latitude": 37.424354, "longitude": -122.09508869999999 },{ "kind": "walletobjects#latLongPoint", "latitude": 37.7901435, "longitude": -122.39026709999997 },{ "kind": "walletobjects#latLongPoint", "latitude": 40.7406578, "longitude": -74.00208940000002 }], "reviewStatus": "underReview", "review": { "comments": "Real auto approval by system" }, "textModulesData": [ { "header": "Details", "body": "20% off one cup of coffee at all Baconrista Coffee locations. " + "Only one can be used per visit." }, { "header": "About Baconrista", "body": "Since 2013, Baconrista Coffee has been committed to making high " + "quality bacon coffee. Visit us in our stores or online at www.baconrista.com" } ], "linksModuleData": { "uris": [ { "kind": "walletobjects#uri", "uri": "https://maps.google.com/map?q=google", "description": "Nearby Locations" }, { "kind": "walletobjects#uri", "uri": "tel:6505555555", "description": "Call Customer Service" } ] }, "imageModulesData": [ { "mainImage": { "kind": "walletobjects#image", "sourceUri": { "kind": "walletobjects#uri", "uri": "https://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg", "description": "Coffee beans" } } } ], "hexBackgroundColor": "#ffffff", "heroImage": { "kind": "walletobjects#image", "sourceUri": { "kind": "walletobjects#uri", "uri": "https://farm8.staticflickr.com/7302/11177240353_115daa5729_o.jpg" } } }
자바
// Define the Image Module Data List<ImageModuleData> imageModuleData = new ArrayList<ImageModuleData>(); ImageModuleData image = new ImageModuleData().setMainImage( new Image().setSourceUri( new ImageUri().setUri("http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"))); imageModuleData.add(image); // Define Links Module Data List<Uri> uris = new ArrayList<Uri>(); Uri uri1 = new Uri().setDescription("Nearby Locations").setUri("http://maps.google.com/?q=google"); Uri uri2 = new Uri().setDescription("Call Customer Service").setUri("tel:6505555555"); uris.add(uri1); uris.add(uri2); LinksModuleData linksModuleData = new LinksModuleData().setUris(uris); // Define Text Areas List<TextModuleData> textModulesData = new ArrayList<TextModuleData>(); TextModuleData details = new TextModuleData().setHeader("Details").setBody( "20% off one cup of coffee at all Baconrista Coffee locations. Only one can be used per visit."); TextModuleData finePrint = new TextModuleData().setHeader("About Baconrista").setBody( "Since 2013, Baconrista Coffee has been committed to making high quality bacon coffee. Visit us in our stores or online at www.baconrista.com"); textModulesData.add(details); textModulesData.add(finePrint); // Define Geofence locations List<LatLongPoint> locations = new ArrayList<LatLongPoint>(); locations.add(new LatLongPoint().setLatitude(37.422601).setLongitude( -122.085286)); locations.add(new LatLongPoint().setLatitude(37.424354).setLongitude( -122.09508869999999)); locations.add(new LatLongPoint().setLatitude(40.7406578).setLongitude( -74.00208940000002)); OfferClass wobClass = new OfferClass() .setId('2945482443380251551.ExampleOfferClass1') .setIssuerName("Baconrista Coffee") .setTitle("20% off one bacon fat latte") .setProvider("Baconrista Deals") .setTitleImage( new Image().setSourceUri(new ImageUri() .setUri("http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"))) .setRedemptionChannel("both") .setReviewStatus("underReview") .setLinksModuleData(linksModuleData) .setImageModulesData(imageModuleData) .setTextModulesData(textModulesData) .setLocations(locations).setMultipleDevicesAndHoldersAllowedStatus("multipleHolders"); OfferClass response = client.offerclass().insert(wobClass).execute();
PHP
// A list of locations at which the Wallet Class can be used. $locations = array( array( 'kind' => 'walletobjects#latLongPoint', 'latitude' => 37.424015499999996, 'longitude' => -122.09259560000001 ), array( 'kind' => 'walletobjects#latLongPoint', 'latitude' => 37.424354, 'longitude' => -122.09508869999999 ), array( 'kind' => 'walletobjects#latLongPoint', 'latitude' => 37.7901435, 'longitude' => -122.39026709999997 ), array( 'kind' => 'walletobjects#latLongPoint', 'latitude' => 40.7406578, 'longitude' => -74.00208940000002 ) ); // Source uri of title image. $uriTitleImageInstance = new Google_Service_Walletobjects_ImageUri(); $imageTitleImageInstance = new Google_Service_Walletobjects_Image(); $uriTitleImageInstance->setUri( 'http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg' ); $imageTitleImageInstance->setSourceUri($uriTitleImageInstance); // Define text module data. $textModulesData = array( array( 'header' => 'Details', 'body' => '20% off one cup of coffee at all Baconrista Coffee locations. ' . 'Only one can be used per visit.' ), array( 'header' => 'About Baconrista', 'body' => 'Since 2013, Baconrista Coffee has been committed to making high ' . 'quality bacon coffee. Visit us in our stores or online at www.baconrista.com' ) ); // Define links module data. $linksModuleData = new Google_Service_Walletobjects_LinksModuleData(); $uris = array ( array( 'uri' => 'http://maps.google.com/map?q=google', 'kind' => 'walletobjecs#uri', 'description' => 'Nearby Locations' ), array( 'uri' => 'tel:6505555555', 'kind' => 'walletobjecs#uri', 'description' => 'Call Customer Service' ) ); $linksModuleData->setUris($uris); $uriModuleImageInstance = new Google_Service_Walletobjects_ImageUri(); $uriModuleImageInstance->setUri( 'http://farm8.staticflickr.com/7401/11177116434_d8e600bba6_o.jpg' ); $uriModuleImageInstance->setDescription('Coffee beans'); $imageModuleImageInstance = new Google_Service_Walletobjects_Image(); $imageModuleImageInstance->setSourceUri($uriModuleImageInstance); $imagesModuleData = new Google_Service_Walletobjects_ImageModuleData(); $imagesModuleData->setMainImage($imageModuleImageInstance); $imagesModuleDataArr = array ($imagesModuleData); // Create wallet class. $wobClass = new Google_Service_Walletobjects_OfferClass(); $offerClass->setId('2945482443380251551.OfferClass'); $wobClass->setIssuerName('Baconrista Coffee'); $wobClass->setTitle('20% off on one bacon fat latte'); $wobClass->setProvider('Baconrista Deals'); $wobClass->setTitleImage($imageTitleImageInstance); $wobClass->setLinksModuleData($linksModuleData); $wobClass->setTextModulesData($textModulesData); $wobClass->setImageModulesData($imagesModuleDataArr); $wobClass->setRedemptionChannel('both'); $wobClass->setReviewStatus('underReview'); $wobClass->setLocations($locations); $wobClass->setMultipleDevicesAndHoldersAllowedStatus('multipleHolders'); $service->offerclass->insert($wobClass);
Python
api_object = generate_offer_class( '1234567', 'ExampleOfferClass') api_request = service.offerclass().insert(body=api_object) api_response = api_request.execute() def generate_offer_class(issuer_id, class_id): offer_class = { 'kind': 'walletobjects#offerClass', 'id': '%s.%s' % (issuer_id, class_id), 'issuerName': 'Baconrista Coffee', 'title': '20% off one bacon fat latte', 'redemptionChannel': 'both', 'provider': 'Baconrista Deals', 'titleImage': { 'kind': 'walletobjects#image', 'sourceUri': { 'kind': 'walletobjects#uri', 'uri': 'http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg' } }, 'multipleDevicesAndHoldersAllowedStatus': 'multipleHolders', 'locations': [{ 'kind': 'walletobjects#latLongPoint', 'latitude': 37.424015499999996, 'longitude': -122.09259560000001 },{ 'kind': 'walletobjects#latLongPoint', 'latitude': 37.424354, 'longitude': -122.09508869999999 },{ 'kind': 'walletobjects#latLongPoint', 'latitude': 37.7901435, 'longitude': -122.39026709999997 },{ 'kind': 'walletobjects#latLongPoint', 'latitude': 40.7406578, 'longitude': -74.00208940000002 }], 'reviewStatus': 'underReview', 'review': { 'comments': 'Real auto approval by system' }, 'textModulesData': [{ 'header': 'Details', 'body': '20% off one cup of coffee at all Baconrista Coffee locations. ' + 'Only one can be used per visit.' },{ 'header': 'About Baconrista', 'body': 'Since 2013, Baconrista Coffee has been committed to making high ' + 'quality bacon coffee. Visit us in our stores or online at www.baconrista.com' }], 'linksModuleData': { 'uris': [ { 'kind': 'walletobjects#uri', 'uri': 'http://maps.google.com/map?q=google', 'description': 'Nearby Locations' },{ 'kind': 'walletobjects#uri', 'uri': 'tel:6505555555', 'description': 'Call Customer Service' }] }, 'imageModulesData': [ { 'mainImage': { 'kind': 'walletobjects#image', 'sourceUri': { 'kind': 'walletobjects#uri', 'uri': 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg', 'description': 'Coffee beans' } } } ], } return offer_class
JSON OfferObject
다음 샘플은 OfferObject
를 정의합니다.
리소스
{ "kind": "walletobjects#offerObject", "classId": "2945482443380251551.OfferClass", "id": "2945482443380251551.OfferObject", "state": "active", "barcode": { "kind": "walletobjects#barcode", "type": "upcA", "value": "123456789012", "alternateText": "12345" }, "validTimeInterval": { "kind": "walletobjects#timeInterval", "start": { "date": "2013-06-12T23:20:50.52Z" }, "end": { "date": "2013-12-12T23:20:50.52Z" } } }
자바
// Define Barcode Barcode barcode = new Barcode().setType("upcA").setValue("123456789012") .setAlternateText("12345"); // Define Wallet Object OfferObject object = new OfferObject() .setClassId('2945482443380251551.ExampleOfferClass1') .setId('2945482443380251551.ExampleOfferObject1') .setBarcode(barcode) .setValidTimeInterval(new TimeInterval().setEnd(new DateTime().setDate(new com.google.api.client.util.DateTime( new Date().getTime() + 263000000000L)))) .setState("active");
PHP
$barcode = new Google_Service_Walletobjects_Barcode(); $barcode->setType('upcA'); $barcode->setValue('123456789012'); $barcode->setAlternateText('12345'); $validTimeInterval = new Google_TimeInterval(); $startDateTime = new Google_DateTime(); $startDateTime->setDate('2013-06-12T23:20:50.52Z'); $validTimeInterval->setStart($startDateTime); $endDateTime = new Google_DateTime(); $endDateTime->setDate('2013-12-12T23:20:50.52Z'); $validTimeInterval->setEnd($endDateTime); // Create wallet object. $offerObject = new Google_Service_Walletobjects_OfferObject(); $offerObject->setClassId('2945482443380251551.OfferClass'); $offerObject->setId('2945482443380251551.OfferObject'); $offerObject->setBarcode($barcode); $offerObject->setValidTimeInterval($validTimeInterval); $offerObject->setState('active');
Python
offer_object = { 'kind': 'walletobjects#offerObject', 'classId': '1234567.ExampleOfferClass', 'id': '1234567.ExampleOfferObject', 'state': 'active', 'barcode': { 'kind': 'walletobjects#barcode', 'type': 'upcA', 'value': '123456789012', 'alternateText': '12345' } }
OfferObject
를 삽입하는 방법에는 두 가지가 있습니다.
첫 번째 방법은 다음 REST URI에 POST
요청을 수행하는 것입니다(본문에 객체를 정의함).
https://walletobjects.googleapis.com/walletobjects/v1/offerObject
두 번째 방법은 OfferObject
정의에서 JWT를 만들어 이 JWT를 Google Pay에 저장 버튼에 넣는 것입니다. 자세한 내용은 웹 버튼 추가를 참조하세요.
Android API를 사용하여 OfferObject 추가
다음 예시에서는 Android API 월렛 SDK 패키지를 사용하여 OfferObject
를 삽입하는 방법을 보여줍니다.
// Define Text Module Data ListtextModulesData = new ArrayList (); TextModuleData textModuleData = new TextModuleData("Details", "20% off one coffee beverage." + "Offer valid 30 days from date of issue. Not applicable with other offers. Offer" + " must be presented at time of purchase. Offer not valid on non coffee based beverages"); textModulesData.add(textModuleData); // Define Links Module Data List uris = new ArrayList (); UriData uri1 = new UriData("http://www.baconrista.com/myaccount?id=1234567890","My Baconrista account"); uris.add(uri1); List imageUris = new ArrayList (); UriData uri2 = new UriData("http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg", "Image Description"); imageUris.add(uri2); // Define Info Module List row0cols = new ArrayList (); LabelValue row0col0 = new LabelValue("Next Reward in","2 coffees"); LabelValue row0col1 = new LabelValue("Member Since", "01/15/2013"); row0cols.add(row0col0); row0cols.add(row0col1); List row1cols = new ArrayList (); LabelValue row1col0 = new LabelValue("Local Store", "Mountain View"); row1cols.add(row1col0); List rows = new ArrayList (); LabelValueRow row0 = LabelValueRow.newBuilder().addColumns(row0cols).build(); LabelValueRow row1 = LabelValueRow.newBuilder().addColumns(row1cols).build(); rows.add(row0); rows.add(row1); // Define general messages List messages = new ArrayList (); WalletObjectMessage message = WalletObjectMessage.newBuilder() .setHeader("Hi Jane!") .setBody("Thanks for being a great customer.") .build(); messages.add(message); // Define Geolocations LatLng location = new LatLng(37.422601, -122.085286); List locations = new ArrayList (); locations.add(location); Date time = new Date(); OfferWalletObject wob = OfferWalletObject .newBuilder() .setClassId("2951238800106304306.OfferClassMonster3") .setId("2951238800106304306.OfferTestObject1") .setState(WalletObjectsConstants.State.ACTIVE) .setIssuerName("Baconrista") .setTitle("20% off coffee") .setValidTimeInterval(new TimeInterval(time.getTime(), time.getTime() + 144000000L)) .setBarcodeType("qrCode") .setBarcodeValue("28343E3") .setBarcodeAlternateText("12345") .addTextModulesData(textModulesData) .addLinksModuleDataUris(uris) .addInfoModuleDataLabelValueRows(rows) .addImageModuleDataMainImageUris(imageUris) .addMessages(messages) .addLocations(locations) .build(); return wob; } }
자세한 내용은 Google Pay에 패스 저장을 참조하세요.