Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 98 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | // Fivestars Partner API |
| 4 | // Sample PHP SDK |
| 5 | // Propietary & Confidential |
| 6 | // Copyright FiveStars Loyalty LLC. |
| 7 | |
| 8 | include('fivestarspartnerapi.php'); |
| 9 | |
| 10 | // API URL |
| 11 | $api_url = 'https://api.partnersandbox.fivestars.com/api/unified/'; |
| 12 | |
| 13 | // Your Fivestars Partner API Credentials |
| 14 | $api_key = ''; |
| 15 | $api_secret = ''; |
| 16 | |
| 17 | // Your Store ID |
| 18 | $store_id = ''; |
| 19 | |
| 20 | // Optional: Your Software ID if you know it |
| 21 | $software_id = ''; |
| 22 | |
| 23 | //Phone Number of a new Member to add |
| 24 | $customer_phone_number = '5555555555'; |
| 25 | |
| 26 | if (!$api_key || !$api_secret || (!$store_id && !$software_id) || !$customer_phone_number) { |
| 27 | echo 'Missing credentials for the examples!' . "\n"; |
| 28 | echo 'Please open examples.php and add your credentials.' . "\n"; |
| 29 | die(); |
| 30 | } |
| 31 | |
| 32 | // Set up the API client |
| 33 | $fivestars_partner_api = new FivestarsPartnerApi( |
| 34 | $api_url, |
| 35 | $api_key, |
| 36 | $api_secret |
| 37 | ); |
| 38 | |
| 39 | |
| 40 | /* |
| 41 | * |
| 42 | * Retrieve Business Location Information |
| 43 | * |
| 44 | */ |
| 45 | $business_result = $fivestars_partner_api->api_call( |
| 46 | 'partners/' . $store_id |
| 47 | ); |
| 48 | echo 'Retrieve Business Location Information' . "\n"; |
| 49 | print_r($business_result); |
| 50 | if ($software_id == '') { |
| 51 | $software_id = $business_result['business_software_id']; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /* |
| 56 | * |
| 57 | * Retrieve Reward Information |
| 58 | * |
| 59 | */ |
| 60 | $rewards_result = $fivestars_partner_api->api_call( |
| 61 | 'businesses/' . $software_id . '/rewards' |
| 62 | ); |
| 63 | echo 'Retrieve Reward Information' . "\n"; |
| 64 | print_r($rewards_result); |
| 65 | |
| 66 | |
| 67 | /* |
| 68 | * |
| 69 | * Retrieve Information About a Single Member |
| 70 | * |
| 71 | */ |
| 72 | $phone_hash = sha1($customer_phone_number); |
| 73 | $endpoint = ( |
| 74 | 'businesses/' . |
| 75 | $software_id . '/' . |
| 76 | 'memberships/' . |
| 77 | 'by-phone/' . |
| 78 | $phone_hash |
| 79 | ); |
| 80 | $get_member_result = $fivestars_partner_api->api_call( |
| 81 | $endpoint |
| 82 | ); |
| 83 | echo "Retrieve Information About a Single Member" . "\n"; |
| 84 | print_r($get_member_result); |
| 85 | |
| 86 | |
| 87 | // WARNING - Below this line creates new data! |
| 88 | /* |
| 89 | * |
| 90 | * Create a New Membership |
| 91 | * |
| 92 | */ |
| 93 | $endpoint = ( |
| 94 | 'businesses/' . |
| 95 | $software_id . '/' . |
| 96 | 'memberships' |
| 97 | ); |
| 98 | $add_member_result = $fivestars_partner_api->api_call( |
| 99 | $endpoint, |
| 100 | array( |
| 101 | 'phone' => $customer_phone_number |
| 102 | ) |
| 103 | ); |
| 104 | echo "Create a New Membership" . "\n"; |
| 105 | print_r($add_member_result); |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | * |
| 110 | * Update an Existing Membership Record |
| 111 | * |
| 112 | */ |
| 113 | $phone_hash = $fivestars_partner_api->phone_hash($customer_phone_number); |
| 114 | $endpoint = ( |
| 115 | 'businesses/' . |
| 116 | $software_id . '/' . |
| 117 | 'memberships/' . |
| 118 | 'by-phone/' . |
| 119 | $phone_hash |
| 120 | ); |
| 121 | $edit_member_result = $fivestars_partner_api->api_call( |
| 122 | $endpoint, |
| 123 | array( |
| 124 | 'notes' => 'Examples note update PHP Client.' |
| 125 | ), |
| 126 | true |
| 127 | ); |
| 128 | echo "Update an Existing Membership Record" . "\n"; |
| 129 | print_r($edit_member_result); |
| 130 | |
| 131 | |
| 132 | /* |
| 133 | * |
| 134 | * Award Points & Redeem Rewards |
| 135 | * |
| 136 | */ |
| 137 | $endpoint = ( |
| 138 | 'businesses/' . |
| 139 | $software_id . '/' . |
| 140 | 'sales' |
| 141 | ); |
| 142 | $add_points_result = $fivestars_partner_api->api_call( |
| 143 | $endpoint, |
| 144 | array( |
| 145 | "phone" => $customer_phone_number, |
| 146 | "points" => [["amount" => 10]], |
| 147 | "checkin" => "partner", |
| 148 | ) |
| 149 | ); |
| 150 | echo "Award Points & Redeem Rewards" . "\n"; |
| 151 | print_r($add_points_result); |
| 152 | $sale_uid = $add_points_result['uid']; |
| 153 | |
| 154 | |
| 155 | /* |
| 156 | * |
| 157 | * Retrieve Sale Information |
| 158 | * |
| 159 | */ |
| 160 | $endpoint = ( |
| 161 | 'businesses/' . |
| 162 | $software_id . '/' . |
| 163 | 'sales/' . |
| 164 | $sale_uid |
| 165 | ); |
| 166 | $get_sale_result = $fivestars_partner_api->api_call( |
| 167 | $endpoint |
| 168 | ); |
| 169 | echo "Retrieve Sale Information" . "\n"; |
| 170 | print_r($get_sale_result); |