Git Product home page Git Product logo

ibm / customer-loyalty-program Goto Github PK

View Code? Open in Web Editor NEW
63.0 20.0 79.0 4.14 MB

# WARNING: This repository is no longer maintained :warning: This pattern focuses on older technology (e.g. Hyperledger Fabric APIs prior to Fabric 1.4). Therefore, there is no support for this pattern and it will be archived on May 1, 2019. You are welcome to use up to that date, but we recommend that you begin working with the updated release found at https://developer.ibm.com/patterns/customer-loyalty-program-with-iks-saas-v2-fabric/.

Home Page: https://developer.ibm.com/patterns/customer-loyalty-program-with-blockchain/

License: Apache License 2.0

Shell 24.05% JavaScript 42.29% HTML 31.33% CSS 2.33%

customer-loyalty-program's Introduction

WARNING: This repository is no longer maintained ⚠️

This pattern focuses on older technology (e.g. Hyperledger Fabric APIs prior to Fabric 1.4). Therefore, there is no support for this pattern and it will be archived on May 1, 2019. You are welcome to use up to that date, but we recommend that you begin working with the updated release found at https://developer.ibm.com/patterns/customer-loyalty-program-with-iks-saas-v2-fabric/.

Customer Loyalty Program with blockchain

A customer loyalty program allows companies to reward customers who frequently make purchases. Program members are able to earn points on purchases, which can translate into some type of reward such as discount, freebie or special customer treatment. The members work toward a certain amount of points to redeem their reward. These programs can have multiple companies as partners on the program, to cater to a customer base. However, current loyalty program systems are restraint on relations between partners, and with visibility to members. These restraints can be removed by creating the customer loyalty program on a blockchain network.

This blockchain model for a customer loyalty program enhances the value of points to loyalty program members and brings in new value to the partners by creating trusted transactions. Participants in this network have a more level relation among each other and points are in the centric position to connect all participants.

In this code pattern, we will create a customer loyalty program as a blockchain web application using Hyperledger Composer API and Node.js. The application will allow members to register on the network where they will create their account. They will be identified on the network with their account number and will create a access key which they will use to sign in. This access key is used as the card id for the member to make transactions and query records. The member once signed in, can make transactions to earn points and redeem points from the partners on the network. They can view their transactions as part of the blockchain ledger. This code pattern illustrates the use of permissions as part of the network where a member can only view their transactions.

Similarly for the partner, they will register by creating an identity on the network and an access key which will be used to view their records. Partners are allowed to view only transactions they were part of, and thus can keep track of all their transactions where they allocated or redeemed points. The web application shows a basic dashboard for the partner displaying the total points that they have allocated and redeemed to members. As transactions get complex, the partner can perform analysis on their transactions to create informative dashboards.

This code pattern is for developers looking to start building blockchain applications with Hyperledger Composer. When the reader has completed this code pattern, they will understand how to:

  • Create basic business network using Hyperledger Composer framework
  • Deploy the network to an instance of Hyperledger Fabric locally or on IBM Blockchain Starter Plan
  • Build a Node.js web application to interact with the blockchain network using Composer API

Architecture Flow

Note The blockchain network will have multiple members and partners

  1. Member is registered on the network
  2. Member can sign-in to make transactions to earn points, redeem points and view their transactions
  3. Partner is registered on the network
  4. Partner can sign-in to view their transactions and display dashboard

Included Components

  • Hyperledger Composer v0.19.4 Hyperledger Composer is an extensive, open development toolset and framework to make developing blockchain applications easier
  • Hyperledger Fabric v1.1 Hyperledger Fabric is a platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility and scalability.
  • IBM Blockchain Starter Plan The IBM Blockchain Platform Starter Plan allows to build and try out blockchain network in an environment designed for development and testing

Featured technology

  • Nodejs Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code server-side
  • Bootstrap Bootstrap is an open source toolkit for developing with HTML, CSS, and JS

Running the Application

Follow these steps to setup and run this code pattern. The steps are described in detail below.

Prerequisite

  • npm (v5.x)
  • Node (version 8.9 or higher - note version 9 is not supported)
  • to install specific Node version you can use nvm

    Example:

      1. nvm install 8.9.4
      1. nvm use v8.9.4
      1. Output Now using node v8.9.4 (npm v6.1.0)

Steps

  1. Clone the repo
  2. Generate the Business Network Archive
  3. Deploy Network
  4. Run Application

1. Clone the repo

Clone the Customer Loyalty Program with Blockchain repo locally. In a terminal, run:

git clone https://github.com/IBM/customer-loyalty-program

2. Generate the Business Network Archive

Next we will generate the Business Network Archive (BNA) file from the root directory.
This file will contain your network including:

  • the model defined in the org.clp.biznet.cto file in the models folder
  • the logic behind transactions in the logic.js file in the lib folder
  • permissions defined in the permissions.acl file
  • queries defined in the queries.qry file

Run the following the command to create the bna file:

cd customer-loyalty-program/
npm install

The composer archive create command in package.json has created a file called [email protected].

3. Deploy Network

The bna can be deployed to a local instance of Fabric or can use IBM Blockchain Starter Plan.

4. Run Application

Go into the web-app folder and install the dependency:

cd web-app/
npm install

Start the application:

npm start

The application should now be running at: http://localhost:8000


Deploy application to IBM Cloud

If your hosting the network on IBM Blockchain Starter Plan, then you can deploy the app to IBM Cloud.

Links

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

customer-loyalty-program's People

Contributors

kkbankol-ibm avatar ljbennett62 avatar raheelzubairy avatar stevemart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

customer-loyalty-program's Issues

Error code MVCC_READ_CONFLICT

Hi All,

I tried to do multiple transactions and have error below.

Error: Error trying invoke business network with transaction id 87c91cb2cd7e7a232466b20d017ad2c3417e6d87ed7aa8a8bef8a3f934526277. Error: Peer localhost:7051 has rejected transaction '87c91cb2cd7e7a232466b20d017ad2c3417e6d87ed7aa8a8bef8a3f934526277' with code MVCC_READ_CONFLICT

The scenario: when a Member earns Points through Purchase, there are 2 transactions:

  • the 1st transaction is Earn Points transaction to update Member data
  • the 2nd transaction is update Partner data to have new balance = pointquota - eraned-points

I have added pointquota and balance in Partner model as:
participant Partner identified by id {
o String id
o String name
o Integer pointquota default=1000
o Integer balance
}

Any idea how to fix this? If I simply separate 2 transactions by using GUI (click buttons in html page), the 2 transaction went thought.

Thx in advance.

Error when using command "composer network install ..."

Hi all,

I followed the instruction to deploy network to Fabric locally as below:

  1. Removing all running containers, and all previously created Hyperledger Fabric chaincode images:
    docker kill $(docker ps -q)
    docker rm $(docker ps -aq)
    docker rmi $(docker images dev-* -q)

  2. Start fabric and create peer admin card:
    cd fabric-dev-servers/
    ./downloadFabric.sh
    => OK
    ./startFabric.sh
    => )K
    ./createPeerAdminCard.sh
    Error: "v0.19.x is not supported for this level of fabric. Please use version 0.16"...

So I uninstall all v0.19.x and install v0.16.0 by commands:

npm uninstall composer-cli
npm uninstall composer-rest-server
npm uninstall -g generator-hyperledger-composer

Then install version 0.16:

npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]

After that, I do step 2 above :
Start fabric and create peer admin card:

cd fabric-dev-servers/
./downloadFabric.sh
=> OK
./startFabric.sh
=> )K
./createPeerAdminCard.sh
=> OK

Then I do next step:
3) Install the business network:

cd ../
composer network install --card PeerAdmin@hlfv1 --archiveFile [email protected]
Error: Incorrect command. Please see the list of commands above, or enter "composer network --help".

Found that my composer version is now v0.16.0, which is not support command "composer network install ...". Only composer version is now v0.19.x onward allows to use command "composer network install ...". Thus I stuck there because if use composer version v0.19.x, there is error in step 2) Start fabric and create peer admin card saying that "v0.19.x is not supported for this level of fabric.", However, if I use version v0.16.0, there is error in step 3) Install the business network saying that this version does not support command "composer network install ...".

Any help?

Thx in advance.

Issue with Partner permissions entry

I'm trying to understand the ins and outs of permissions and rules and couldn't figure this one out.
Is there is an issue with this partner rule condition:

//Partners Not to have access to other member accounts
rule PartnerAccessPartner {
description: "Allow memebers to access only their profile"
participant(p): "org.clp.biznet.Partner"
operation: ALL
resource(r): "org.clp.biznet.Partner"
condition: (r.getIdentifier() === p.getIdentifier())
action: DENY
}

I think the condition should be removed from this rule to make it effective - this seems to only block a partner from ALL operations on their own account.

Idcard error

Getting error when executing...
./createPeerAdmin.sh
Using composer-cli at v0.19.4
Typeerror: IdCard is not a constructor
Error: Unable to read file: /tmp/[email protected]
Typeerror: Admin connection is not a constructor

step 2 - Generate the Business Network Archive

I'm running into an issue when i run the command
npm install
Here is the error I get.
Jaishankars-MacBook-Pro:customer-loyalty-program [email protected]$ npm install

[email protected] install /Users/[email protected]/Client/BlockChain/customer-loyalty-program/node_modules/node-report
node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

Traceback (most recent call last):
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 16, in
sys.exit(gyp.script_main())
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/init.py", line 545, in script_main
return main(sys.argv[1:])
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/init.py", line 538, in main
return gyp_main(args)
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/init.py", line 523, in gyp_main
generator.GenerateOutput(flat_list, targets, data, params)
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2170, in GenerateOutput
part_of_all=qualified_target in needed_targets)
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 795, in Write
self.Pchify))
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1190, in WriteSources
cflags = self.xcode_settings.GetCflags(configname)
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 551, in GetCflags
archs = self.GetActiveArchs(self.configname)
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 420, in GetActiveArchs
xcode_archs_default = GetXcodeArchsDefault()
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 118, in GetXcodeArchsDefault
xcode_version, _ = XcodeVersion()
File "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py", line 1265, in XcodeVersion
version = re.match(r'(\d.\d.?\d*)', version).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/Users/[email protected]/.nvm/versions/node/v8.9.1/bin/node" "/Users/[email protected]/.nvm/versions/node/v8.9.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/[email protected]/Client/BlockChain/customer-loyalty-program/node_modules/node-report
gyp ERR! node -v v8.9.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN [email protected] requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/[email protected]/.npm/_logs/2018-08-15T21_03_26_338Z-debug.log

need help.

Error in permissions.acl file

In the permissions.acl file, there is an error on line 81 and 83 (aliases are present when there is no condition), and that's throwing the following error:

ParseException: Expected "condition:", "transaction", comment, end of line or whitespace but "a" found. File permissions.acl line 84 column 5
Command failed

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] prepublish: composer archive create -t dir -n .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alexanderalbasosi/.npm/_logs/2018-06-24T13_41_57_839Z-debug.log

Was fixed by removing the aliases (p for participant and r for resource).

member Registeration failed

peeradmincard created successfully through command $ ./createPeerAdminCard.sh also i got the following output when run [ $ composer card list ] command

composer card list
The following Business Network Cards are available:

Connection Profile: hlfv1
┌─────────────────┬───────────┬──────────────────┐
│ Card Name │ UserId │ Business Network │
├─────────────────┼───────────┼──────────────────┤
│ PeerAdmin@hlfv1 │ PeerAdmin │ │
└─────────────────┴───────────┴──────────────────┘
Issue composer card list --card to get details a specific card
Command succeeded

My problem is : when i opened the application at address [ http://localhost:8000/registerMember ] and entered everything like userid ..etc i got the following error [ Card not found: admin@clp-network ]

any advise please ?

Clarification on terminology

I couldn't find where to ask this so here it goes:

Is a partner here (a company) the same as a "membership of an organization" in the IBM cloud plans?

Is a member here (a customer redeeming points) the same as a "small peer" in the IBM cloud plans?

What are the limitations?

Cannot connect to network with non-admin cardId on cloud

The application is fully functional if use locally deployed network. When I tried deploying the network to cloud, the members/partners are created with no problem using admin card, however, I'm getting ECONNREFUSED error on logging in as a member/partner.

Here's the error log

memberData using param -  accountNumber: 000002 cardId: ACID000002
Error: Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]
    at client.getUserContext.then.then.catch (/Users/seondongkim/Documents/Hyperledger/customer-loyalty-program/web-app/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:395:34)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Error: Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]
    at client.getUserContext.then.then.catch (/Users/seondongkim/Documents/Hyperledger/customer-loyalty-program/web-app/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:395:34)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:30961) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
(node:30961) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

and here's the list of cards

Connection Profile: Alps Network - 8h5
┌──────────────────────────┬────────┬──────────────────┐
│ Card Name                │ UserId │ Business Network │
├──────────────────────────┼────────┼──────────────────┤
│ admin@Alps-Network---8h5 │ admin  │                  │
├──────────────────────────┼────────┼──────────────────┤
│ admin@clp-network        │ admin  │ clp-network      │
└──────────────────────────┴────────┴──────────────────┘


Connection Profile: hlfv1
┌────────────┬────────────┬──────────────────┐
│ Card Name  │ UserId     │ Business Network │
├────────────┼────────────┼──────────────────┤
│ ACID000001 │ ACID000001 │ clp-network      │
├────────────┼────────────┼──────────────────┤
│ ACID000002 │ ACID000002 │ clp-network      │
├────────────┼────────────┼──────────────────┤
│ ACID100001 │ ACID100001 │ clp-network      │
└────────────┴────────────┴──────────────────┘

I tried following the instruction precisely step-by-step but I'm not sure if I did wrong somewhere or this is how it is written. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.