{"_id":"56cd503649abf10b0036a1f0","title":"Getting Started","githubsync":"","slug":"getting-started","sync_unique":"","createdAt":"2016-02-24T06:39:50.728Z","hidden":false,"isReference":false,"parentDoc":null,"project":"56cacb1bc675f50b00a4b619","api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"category":"579525172979790e00771a15","updates":[],"user":"56caca84245b841300806def","version":"56cacb1cc675f50b00a4b61c","body":"Using the SDK is straight forward and simple. The SDK consist of four main services\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"1. Sign up for a Codemojo account\"\n}\n[/block]\nCreate a Codemojo account from [this link](https://dashboard.codemojo.io) \n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"2. Enable and configure the services\"\n}\n[/block]\n* Once inside the Codemojo dashboard, you can head on to the `Set up Services` section from the left menu\n* Enable `Wallet` & `Loyalty` services to begin with\n* Click on the small down arrow and click on `Configure Loyalty`\n* Set up the service as per your requirement\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"3. Download the SDK\"\n}\n[/block]\nDownload the SDK from the below links\n\n* [PHP](https://github.com/codemojo-dr/startkit-php-sdk/archive/master.zip)\n* [Android](https://github.com/codemojo-dr/startkit-android-sdk/archive/master.zip) \n* [Java](https://github.com/codemojo-dr/startkit-java-sdk/archive/master.zip)\n* [iOS Swift](https://github.com/codemojo-dr/startkit-ios-sdk)\n* Node.js\n* .NET\n* Python\n* Ruby\n* Perl\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"{\\n \\\"require\\\": {\\n \\\"codemojo/startkit\\\": \\\"0.1.*\\\"\\n }\\n}\",\n \"language\": \"json\",\n \"name\": \"PHP Composer Plugin\"\n }\n ]\n}\n[/block]\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"dependencies {\\n compile 'io.codemojo.sdk:sdk:1.0.58+'\\n}\",\n \"language\": \"json\",\n \"name\": \"Android Gradle plugin\"\n }\n ]\n}\n[/block]\nWe are trying hard to get the SDK for all other languages as well, if the SDK for your preferred language is not available you can use our [Rest APIs](doc:getting-oauth-access-token) directly to integrate.\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"4. Get your Keys\"\n}\n[/block]\nFrom the Codemojo dashboard, from the left menu click on the `App Keys` and copy the Client ID & Secret\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"5. Setup the SDK\"\n}\n[/block]\nOnce you have the SDK and the app keys, you need to include the SDK into your project\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n\\t\\n\\trequire_once _PATH_TO_SDK_ . '/sdk/autoload.php';\\n \",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"6. Initialize the Authentication Service\"\n}\n[/block]\nOnce you have setup the SDK in your project, you can initialize the AuthenticationService with your CLIENT_ID and CLIENT_SECRET\n[block:callout]\n{\n \"type\": \"danger\",\n \"title\": \"Exception handling\",\n \"body\": \"Please be sure to include the error callback when initializing the AuthenticationService otherwise the SDK will throw runtime exceptions\"\n}\n[/block]\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n\\n\\t// Include the SDK autoload file\\n\\trequire_once _PATH_TO_SDK_ . '/sdk/autoload.php';\\n\\n\\tuse CodeMojo\\\\Client\\\\Endpoints;\\n\\tuse CodeMojo\\\\Client\\\\Services\\\\AuthenticationService;\\n\\n /*\\n * Initialize the core services\\n */\\n $authenticationService = new AuthenticationService(CLIENT_ID, CLIENT_SECRET, Endpoints::ENV_SANDBOX, function($type, $error){\\n // Log the error / Show the the appropriate error messages for DEBUG purposes\\n Log::assert(\\\"Error: \\\" . $type . \\\": \\\" . $error);\\n });\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"7. Initialize Loyalty Service\"\n}\n[/block]\nLoyalty service takes in Authentication Service as the main parameter & a optional second WalletService parameter\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n \\n use CodeMojo\\\\Client\\\\Services\\\\LoyaltyService;\\n\\n $loyaltyService = new LoyaltyService($authenticationService);\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"8. Rewarding Loyalty Cashback\"\n}\n[/block]\nImagine a scenario where a user is shopping in you mobile app / website and is at the checkout page.\n\nWe will be providing a cashback which will be valid for only 30 days from the day of crediting. The cashback % is the one configured by you in your dashboard.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n\\n $loyaltyService->addLoyaltyPoints( getUserID(), $checkout_price, null, null, 30, $transaction_id, \\\"Cashback for Order ID #\\\" . $transaction_id );\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\nThere will be situations where you might be required to show how much of cashback will the user get if he/she completes the transaction\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n \\n $how_many_points = $loyaltyService->calculateLoyaltyPoints( getUserID(), calculateCartPrice() );\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"9. Redeeming cashback\"\n}\n[/block]\nMost times, you must know how much a user can redeem for the current transaction before the actual redemption. That can be done something like the below \n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n\\n$maximumRedemption = $loyaltyService->maximumRedemption(getUserID(), calculateCartPrice());\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\nOnce you know the actual redemption, you can redeem as follows \n[block:callout]\n{\n \"type\": \"warning\",\n \"title\": \"Redeem after a successful checkout process\",\n \"body\": \"It is recommended that the redemption be done after a successful checkout as there are chances of user cancelling the process during the payments\"\n}\n[/block]\n\n[block:callout]\n{\n \"type\": \"danger\",\n \"title\": \"Exception Handling\",\n \"body\": \"Please make sure to wrap the redeem method with a error handling mechanism, the SDK with throw a `BalanceExhaustedException` when the redemption fails due to low balance\"\n}\n[/block]\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n \\n\\ttry {\\n $loyaltyService->redeem( getUserID(), $redeem, calculateCartPrice(), null, \\\"Redeemed for Order ID #\\\" . $transaction_id );\\n // Redemption succeded\\n } catch (\\\\CodeMojo\\\\Client\\\\Exceptions\\\\BalanceExhaustedException $e) {\\n // Redemption failed, let the user know\\n die('Not enough balance! Balance has been exhausted');\\n }\\n\\n\",\n \"language\": \"php\",\n \"name\": \"\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"10. Transaction history & User details\"\n}\n[/block]\nYou can get the history of transactions for a particular user\n[block:callout]\n{\n \"type\": \"info\",\n \"title\": \"Heads up! PaginatedResults\",\n \"body\": \"A successful call will get you a PaginatedResult which can be iterated over. For more details on the PaginatedResult object, [refer here](doc:paginatedresult)\"\n}\n[/block]\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n \\n $history = $loyaltyService->getWalletService()->getTransactionDetailsForUser( getUserID(),10, null, (int) :::at:::$_GET['page'] );\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\nAnd also the entire history of transaction across your service\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n \\n\\t$history = $loyaltyService->getWalletService()->getAllTransactions();\\n \\n \",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\nOr get details about a particular transaction\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n\\n\\t$transaction_detail = $loyaltyService->getWalletService()->getTransactionDetail( 'transaction_id' );\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\nYou can also get the snapshot about a particular user\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"\\n<?php\\n\\n\\t$loyalty_details = $loyaltyService->getUserBrief( getUserID() );\\n\\n\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]","excerpt":"Get started","link_url":"","order":0,"type":"basic","__v":27,"link_external":false,"next":{"description":"","pages":[]},"childrenPages":[]}
Getting Started
Get started