Skip to content

Commit 393c9bb

Browse files
committed
Updates to quickstart
Added updates to the readMe, updated outputs to user on successful methods. Added updated sdk version
1 parent 87a585c commit 393c9bb

File tree

512 files changed

+337
-46683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

512 files changed

+337
-46683
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
*.pem

README.md

+30-4
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,51 @@ Make sure that the file has `extension="grpc.so"` and add the line if it doesn'
3131

3232
For detailed steps visit the [gRPC PHP quickstart](https://grpc.io/docs/languages/php/quickstart/).
3333

34-
2. In the certs folder of the repository add the following three PassKit credential files:
34+
2. Add bindings to composer
35+
To install the bindings via [Composer](http://getcomposer.org/), add the following to `composer.json`:
36+
37+
```json
38+
{
39+
"repositories": [
40+
{
41+
"type": "git",
42+
"url": "https://github.com/passkit/passkit-php-grpc-sdk.git"
43+
}
44+
],
45+
"require": {
46+
"passkit/passkit-php-grpc-sdk": "1.1.70"
47+
}
48+
}
49+
```
50+
51+
Then run `composer install`
52+
53+
Manual Installation
54+
Clone the repo and include `autoload.php`:
55+
56+
```php
57+
require_once('/path/to/passkit-php-grpc-sdk/vendor/autoload.php');
58+
```
59+
60+
3. In the certs folder of the repository add the following three PassKit credential files:
3561
- certificate.pem
3662
- ca-chain.pem
3763
- key.pem
3864

3965
You can disregard the key-java.pem credentials file as it is not compatible with PHP.
4066

41-
3. Now we need to decrypt your `key.pem`. At your project root directory, run `cd ./certs` `openssl ec -in key.pem -out key.pem`.
67+
4. Now we need to decrypt your `key.pem`. At your project root directory, run `cd ./certs` `openssl ec -in key.pem -out key.pem`.
4268
![ScreenShot](images/decrypt-key.png)
4369
For the password use the one-time password that you used for generating the SDK credentials.
4470

4571
Your `key.pem` file should look like below.
4672
![ScreenShot](images/decrypted-key.png)
4773
If you do not see `Proc-Type: 4,ENCEYPTED` on line 2, you have successfully decrypted `key.pem`.
4874

49-
4. Modify the variables with the values for your programs or campaigns in each of the membership, coupons and flights methods. The variables to modify will be at the top of each method.
75+
5. Modify the variables with the values for your programs or campaigns in each of the membership, coupons and flights methods. The variables to modify will be at the top of each method.
5076
![ScreenShot](images/variables.png)
5177

52-
5. To run each method go into the directory, for members `cd membership`, for coupons `cd coupons` and for flights `cd flights`. Then run php plus the name of the method e.g. `php enrol-member.php` to run that method.
78+
6. To run each method go into the directory, for members `cd membership`, for coupons `cd coupons` and for flights `cd flights`. Then run php plus the name of the method e.g. `php enrol-member.php` to run that method.
5379

5480
## Examples
5581
### Membership Cards

composer.json

+6-8
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,27 @@
2121
{
2222
"type": "git",
2323
"url": "https://github.com/passkit/passkit-php-grpc-sdk.git"
24-
},
25-
{
26-
"type": "vcs",
27-
"url": "https://github.com/stanley-cheung/Protobuf-PHP"
2824
}
2925
],
3026
"require": {
3127
"grpc/grpc": "^v1.42.0",
32-
"google/protobuf": "^v3.13.0",
33-
"passkit/passkit-php-grpc-sdk": "1.0.0",
34-
"zircote/swagger-php": "^4.4",
35-
"protobuf-php/protobuf": "^0.1.3"
28+
"google/protobuf": "^v3.21.7",
29+
"passkit/passkit-php-grpc-sdk": "1.1.70"
3630
},
3731
"autoload": {
3832
"psr-4": {
3933
"Analytics\\": "lib/Analytics",
4034
"Cabin_codes\\": "lib/Cabin_codes",
35+
"Ct\\": "lib/Ct",
4136
"Event_tickets\\": "lib/Event_tickets",
4237
"Flights\\": "lib/Flights",
4338
"Io\\": "lib/Io",
4439
"Members\\": "lib/Members",
40+
"Raw\\": "lib/Raw",
41+
"Scheduler\\": "lib/Scheduler",
4542
"Single_use_coupons\\": "lib/Single_use_coupons",
4643
"GPBMetadata\\Io\\": "lib/GPBMetadata/Io",
44+
"GPBMetadata\\Ct\\": "lib/GPBMetadata/Ct",
4745
"GPBMetadata\\Google\\": "lib/extra/GPBMetadata/Google",
4846
"Google\\Api\\": "lib/extra/google/api"
4947
}

coupons/count-coupons.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<?php
2-
3-
4-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
52
require_once "../vendor/autoload.php";
63

74
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
85

96
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN AND OFFER
10-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
11-
$offerId = "base";
7+
$campaignId = "";
8+
$offerId = "";
129
// count-coupons takes search conditions as pagination object and returns the number of coupons who match with the condition.
1310
try {
1411
$ca_filename = "ca-chain.pem";
@@ -28,19 +25,22 @@
2825
// Set the coupon list request body
2926
$listRequest = new Single_use_coupons\ListRequest();
3027
$listRequest->setCouponCampaignId($campaignId);
31-
$filter = new Io\Filter();
28+
$filter = new Io\FieldFilter();
3229
$filter->setFilterField("offerId");
3330
$filter->setFilterValue($offerId);
3431
$filter->setFilterOperator("eq");
35-
$listRequest->setFilters($filter);
32+
$filterGroup = new Io\FilterGroup();
33+
$filterGroup->setFieldFilters([$filter]);
34+
$filters = new Io\Filters();
35+
$filters->setFilterGroups([$filterGroup]);
36+
$listRequest->setFilters($filters);
3637

3738

38-
list($id, $status) = $client->countCouponsByCouponCampaign($listRequest)->wait();
39+
list($result, $status) = $client->countCouponsByCouponCampaign($listRequest)->wait();
3940
if ($status->code !== 0) {
4041
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
4142
}
42-
43-
echo $result->getId() . "/n";
43+
echo "Number of coupons " . $result->getTotal() . "\n";
4444
} catch (Exception $e) {
4545
echo $e;
4646
}

coupons/create-campaign.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<?php
2-
3-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
42
require_once "../vendor/autoload.php";
53

64
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
@@ -24,14 +22,14 @@
2422
// Set the campaign body
2523
$campaign = new Single_use_coupons\CouponCampaign();
2624
$campaign->setName("Quickstart Campaign");
27-
$campaign->setStatus(1, 4);
25+
$campaign->setStatus([1, 4]);
2826

2927
list($id, $status) = $client->createCouponCampaign($campaign)->wait();
3028
if ($status->code !== 0) {
3129
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
3230
}
3331
//You can use the campaignId displayed below for other coupon methods
34-
echo "CampaignId" . $campaign->getId() . "\n";
32+
echo "CampaignId " . $id->getId() . "\n";
3533
} catch (Exception $e) {
3634
echo $e;
3735
}

coupons/create-coupon.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<?php
2-
3-
4-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
52
require_once "../vendor/autoload.php";
63

74
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
85

96
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN, OFFER AND EMAIL
10-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
11-
$offerId = "base";
12-
$email = "[email protected]";
7+
$campaignId = "";
8+
$offerId = "";
9+
$email = "";
1310
// create-coupon takes campaignId, offerId and couponDetails, creates a new coupon record, and sends a welcome email to deliver coupon card url.
1411
// The method returns the coupon id. Coupon id is a part of card url.
1512

@@ -47,8 +44,7 @@
4744
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
4845
}
4946
//You can use the couponId displayed below for other coupon methods
50-
echo "https://pub1.pskt.io/" . $id->getId() . "\n";
51-
echo "CouponId" . $coupon->getId() . "\n";
47+
echo "Coupon URL: https://pub1.pskt.io/" . $id->getId() . "\n";
5248
} catch (Exception $e) {
5349
echo $e;
5450
}

coupons/create-offer.php

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
3+
use Google\Protobuf\Timestamp;
4+
45
require_once "../vendor/autoload.php";
56

67
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
78
// create-offer takes a campaignId of an existing campaign, creates a new template (based of default template), creates an offer, and links this offer to the campaign.
89
// The method returns the offer id.
10+
$campaignId = "";
911
try {
1012
$ca_filename = "ca-chain.pem";
1113
$key_filename = "key.pem";
@@ -32,44 +34,45 @@
3234
$defaultTemplateRequest = new Io\DefaultTemplateRequest();
3335
$defaultTemplateRequest->setProtocol(101);
3436
$defaultTemplateRequest->setRevision(1);
35-
$defaultPassTemplate = new Io\PassTemplate();
36-
37-
$defaultPassTemplate->$templatesclient->getDefaultTemplate($defaultTemplateRequest)->wait();
37+
list($defaultPassTemplate, $status) = $templatesclient->getDefaultTemplate($defaultTemplateRequest)->wait();
3838
if ($status->code !== 0) {
3939
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
4040
}
41-
4241
// If you use the default template, you need to set name, description and timezone because these fields are mandatory.
4342
$defaultPassTemplate->setName("Quickstart");
4443
$defaultPassTemplate->setDescription("quick start sample template");
4544
$defaultPassTemplate->setTimezone("America/New_York");
4645

4746

48-
list($id, $status) = $templatesclient->createTemplate($defaultPassTemplate)->wait();
47+
list($template, $status) = $templatesclient->createTemplate($defaultPassTemplate)->wait();
4948
if ($status->code !== 0) {
5049
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
5150
}
5251

53-
5452
// Set the offer body
5553
$offer = new Single_use_coupons\CouponOffer();
5654
$offer->setId("base");
57-
$offer->setBeforeRedeemPassTemplateId($defaultPassTemplate->getId());
55+
$offer->setCampaignId($campaignId);
56+
$offer->setBeforeRedeemPassTemplateId($template->getId());
5857
$offer->setOfferTitle("BaseOffer");
5958
$offer->setOfferShortTitle("BaseOffer");
6059
$offer->setOfferDetails("Base offer");
61-
$startdate = new DateTime();
62-
$enddate = new DateTime();
63-
$enddate->setDate(2022, 6, 28);
64-
$offer->setIssueStartDate($startdate->getTimestamp());
65-
$offer->setIssueEndDate($enddate->getTimestamp());
60+
$date = new DateTime();
61+
$date->setDate(2023, 6, 24);
62+
$startdate = new Timestamp();
63+
$startdate->setSeconds($date->getTimestamp());
64+
$enddate = new Timestamp();
65+
$date->setDate(2023, 6, 28);
66+
$enddate->setSeconds($date->getTimestamp());
67+
$offer->setIssueStartDate($startdate);
68+
$offer->setIssueEndDate($enddate);
6669

6770
list($id, $status) = $client->createCouponOffer($offer)->wait();
6871
if ($status->code !== 0) {
6972
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
7073
}
7174
//You can use the offerId displayed below for other coupon methods
72-
echo "OfferId" . $offer->getId() . "\n";
75+
echo "Offer created: " . $offer->getId() . "\n";
7376
} catch (Exception $e) {
7477
echo $e;
7578
}

coupons/delete-campaign.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<?php
2-
3-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
42
require_once "../vendor/autoload.php";
53

64
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
75

86
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN, OFFER AND COUPON
9-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
7+
$campaignId = "";
108
// delete-campaign takes the campaignId to delete an existing campaign.
119
try {
1210
$ca_filename = "ca-chain.pem";
@@ -31,6 +29,7 @@
3129
if ($status->code !== 0) {
3230
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
3331
}
32+
echo "Campaign deleted. \n";
3433
} catch (Exception $e) {
3534
echo $e;
3635
}

coupons/get-single-coupon.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
2-
3-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
42
require_once "../vendor/autoload.php";
53

64
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
75

86
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN, OFFER AND COUPON
9-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
10-
$offerId = "base";
7+
$campaignId = "";
8+
$offerId = "";
119
$couponId = "";
1210

1311
// get-single-coupon takes couponId and returns the record of that coupon.
@@ -35,7 +33,7 @@
3533
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
3634
}
3735

38-
echo $result->getId() . "/n";
36+
echo "Coupon Status: " . $id->getStatus() . "\n";
3937
} catch (Exception $e) {
4038
echo $e;
4139
}

coupons/list-coupons.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
2-
3-
4-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
52
require_once "../vendor/autoload.php";
63

74
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
85

96
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN, OFFER AND COUPON
10-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
7+
$campaignId = "";
118

129
// list-coupons takes search conditions as pagination object and returns list of coupon records which match with the conditions.
1310
try {
@@ -35,7 +32,7 @@
3532
echo $coupon->getId() . "\n";
3633
}
3734

38-
echo $result->getId() . "/n";
35+
echo "/n";
3936
} catch (Exception $e) {
4037
echo $e;
4138
}

coupons/redeem-coupon.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
2-
3-
4-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
52
require_once "../vendor/autoload.php";
63

74
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
85

96
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN, OFFER AND COUPON
10-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
7+
$campaignId = "";
118
$couponId = "";
129

1310
// redeem-coupon takes a campaignId of an existing campaign, and couponId of existing coupon to redeem that coupon.
@@ -38,7 +35,7 @@
3835
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
3936
}
4037

41-
echo $result->getId() . "/n";
38+
echo "Coupon: " . $id->getId() . " has been redeemed. \n";
4239
} catch (Exception $e) {
4340
echo $e;
4441
}

coupons/update-coupon.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
2-
3-
4-
require_once "../vendor/passkit/passkit-php-grpc-sdk/lib/extra/google/api/";
52
require_once "../vendor/autoload.php";
63

74
putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");
85

96
// MODIFY WITH THE VARIABLES OF YOUR CAMPAIGN, OFFER AND COUPON
10-
$campaignId = "05faUsEvatLifOwxKWmS0Q";
7+
$campaignId = "";
118
$couponId = "";
129

1310
// update-coupon takes a campaignId of an existing campaign and couponId of existing coupon to update that coupon.
@@ -40,7 +37,7 @@
4037
throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
4138
}
4239

43-
echo $result->getId() . "/n";
40+
echo "Coupon: " . $id->getId() . " has been updated. \n";
4441
} catch (Exception $e) {
4542
echo $e;
4643
}

0 commit comments

Comments
 (0)