Sending sales on a customer from a POS

Principles

Here is a fairly complete scenario : your POS system has a customer database, and when a sale is concluded, after payment you wish to send those information to Adelya

We propose the following script :

  1. check if the customer profile is already known to Adelya based on some key you know (e.g. a reference, an email a cardnumber)
  2. if it exists go to next step otherwise create the member with a persist call of a FidelityMember.
  3. you now know the Adelya member.id, you can create a data object representing a sales ticket using a AdEvent (and if you have line item AdEventDetails)

Some diagrams..

...worth a thousand words

Requests

Search if the member exists (here based on idExternal)


{
 "FidelityMember":{
   "idExternal":"my_pos_key"
  }
}
					
return is : {"ApiReturn":{"code":"ERROR","message":"No object found","errorCode":"3008","errorMessage":"No object found"}}
Search if not exist I create it

{
"FidelityMember":{
 idExternal:"my_pos_key"
 "name":"Jean",
 "firstname":"Dujardin",
 "mobile":"+33601020304",
 "cardnumber":"10001235",
 "address":{         
  "line1":"105 rue de la salade ponsans",         
  "zip":"31400",
  "town":"TOULOUSE",
  "country":"FR"
  }
 }
}
                
return is : {"ApiReturn":{"code":"ok","id":3357030}}

Now I can store the "Sale" (with some details)


{
   "AdEvent":{
          "type":"addCA",
          "member":{
                 "id":3357030
          },
          "idExternal":"TEST1259",
          "fvalue":150.0,
          "details":[
                 {
                        "AdEventDetail":{
                           "class1":"Article test 1",
                           "class10":"test",
                           "quantity":1,
                           "unitValue":50.0,
                           "finalValue":50.0
                        }
                 },
                 {
                        "AdEventDetail":{
                           "class1":"Article test 2",
                           "class10":"test",
                           "quantity":2,
                           "unitValue":50.0,
                           "finalValue":100.0
                        }
                 }
          ]
   }
}
                

Your done !

Reminder : If you have more than one store, you have to indicate in which shop was made the sale (by indicating the group property of the AdEvent) as in the loadfromkeys example.

Checking a coupon code

Principles

Even better, you want to add the possibility for the customer to enter a coupon code and check if ok. Here are the steps :

  • Search a coupon based on a trackcode (limited or not to a given member)
  • if none pop a "we are sorry message"
  • if one, check status and validity date and you're done !
  • if you are not sure you can check the coupon unit on the attached campaign

Requests

Search the coupon with its trackcode

HTTP Get

{
    "Sent" : { "trackcode" : "the entered trackcode" }
}
                    
Note : you can limit the search (and so speed up the search) by limiting the search to a given member, just add a member condition in the Get (eg : member : {id : "id of the member"}).

Coupon not found


{
    "ApiReturn":{
        "code":"ERROR",
        "message":"No object found",
        "errorCode":"3008",
        "errorMessage":"No object found"
    }
}
                    

Coupon found !


{
    "Sent":{
        "id":"11054467",
        "type":"COUPON",
        "date":"2010-03-31 00:00:00",
        "startDate":"2010-03-31 00:00:00",
        "endDate":"2010-04-01 00:00:00",
        "status2":true,
        "dateUpdateStatus2":"2010-03-31 14:05:24",
        "fvalue":"10.0",
        "member":"31416",
        "user":"7",
        "group":{
            "id":"9",
            "codeGroup":"WWWADELYATEST",
            "idExternal":"",
            "salesDescr":"Adelya"
        },
        "tel":"telnumber of the contact ",
        "message":"Here you're 10 euro coupon. thx for your loyalty. regards.",
        "trackCode":"427583854679",

        "providerTrackCode":"4745900401270036801748",
        "media":"SMS",
        "campaign":"4275",
        "idProvider":"5"
    }
}
                    

Alternative :search all coupons valid on a customer

If you wish to display all the valid coupons of customer, you can issue the call below.

HTTP Get

{
    "Sent":{
        "type":"COUPON",
        "member" : {id:"<< memberid >>"},
        "startDate_le":"<< datetime of now >>",
        "or":{
            "endDate_is_null":"true",
            "endDate_gt":"<< datetime of now >>"
        },
        "status1":false,
        "status2":false
    }
}
                    

Check and use

Now you have to check :
  • if status1 is not equal to true, if so : it means cancel
  • if status2 is not equal to true, if so : it means used
  • if we are between "startDate" and "endDate", if this coupon is not yet valid or already expired.

Note : on the above example, the coupon is already used

Additionaly, if you are not sure of the campaign itself, you can use the classical :


{
 "Campaign" : {
     "id" : "here campaign id as listed in the sent above"
   }
}
                    
and check the description, brief and couponUnit attributes returned.

And now let's burn it (i.e. mark it as used)

Base on the trackcode (see note 1), you issue a PUT request, of a usedcoupon Event and setting both the status2 and dateUpdateStatus2 on this coupon (the orginalEvent). More over, for statistics linked to the coupon linked to a purchase, it is required to indicate in the cause attribute the purchase id.
Note 1 : in the below example we use the loadfromkeys operator, but of course if you know the coupon id, you can use it straight away.
Note 2 : for compatibility with coupons usage in loyaltyoperator, we indicate the trackcode in the comment section of the usedcoupon event.


{
 "AdEvent":{
   "type":"usedcoupon",
   "member":{"id":1036980},"comment":"427583854679",
   "originalEvent": {
     "loadFromKeys": { "trackCode":"427583854679"},
     "status2":true,
     "dateUpdateStatus2":"2019-09-19 08:29:24"
   },    "cause": {
     "loadFromKeys": { "idExternal":"{id de l'achat}"}
   }  
  }
}
                    

If you'd like to burn it during a sale, you'll have to use a specific detail for it.

(And, also, we need to add a specific rule to your loyalty program. Please tell your Adelya Project Manager)


{
   "AdEvent":{
          "type":"addCA",
          "member":{
                 "id":3357030
          },
          "idExternal":"TEST1259",
          "fvalue":150.0,
          "details":[
                 {
                        "AdEventDetail":{
                           "detailType":"I",
                           "class1":"Article test 1",
                           "class10":"test",
                           "quantity":1,
                           "unitValue":50.0,
                           "finalValue":50.0
                        }
                 },
                 {
                        "AdEventDetail":{
                           "detailType":"I",
                           "class1":"Article test 2",
                           "class10":"test",
                           "quantity":2,
                           "unitValue":50.0,
                           "finalValue":100.0
                        }
                 },
                 {
                        "AdEventDetail":{
                           "detailType":"C",
                           "class1":"Coupon",
                           "class10":"427583854679" -- coupon.trackCode
                        }
                 }
          ]
   }
}
                

Using the cashback

Principles

Cashback is usually earn through the loyaltyprogram, hence the nbCredit field increase with each purchase. And in your system you may want to allow usage of those earnings

We suppose you already have a purchase stored (addCA see above), so you know the amount to pay and the amount of cashback available.

  • issue a addCredit event of the amount you want to use
  • if no error, you can assume cashback was used
  • else propose another payment method.

Requests

Use credit

HTTP PUT

{
    "AdEvent" : { "type" : "addCredit", "fvalue":-15,"member":{"id":xxxx},"cause":{"id":yyyy} }
}
                    
Note : the cause.id is the addCA id as returned by the first api call.