Giter VIP home page Giter VIP logo

mobile-purchases's Introduction

Mobile Purchases

IOS and Android receipt validation and purchase persistence

Structure of the project

  • The scala part of the project is considered "legacy". It's only kept for very old iOS devices and should be decommissioned once there's only a tiny amount of traffic reaching the service.
  • The Typescript part of the project contains the more modern approach to validating and storing mobile purchases.

Local Setup

Node

Make sure that you are using the Node version specified by the .nvmrc file. We recommend fnm as the Node version manager.

  1. Install yarn: npm install -g yarn
  2. Run yarn to install dependencies
  3. Run local tests: yarn test

Data

There are three Dynamo DB tables:

  • Events (mobile-purchases-<stage>-subscription-events-v2): This table records events as they are received from Google and Apple.
  • Subscriptions (mobile-purchases-<stage>-subscriptions): This table records subscriptions held by our users. It contains information such as start date, expiration date, type of subscription and whether it will automatically renew at the end of its validity.
  • UserSubscriptions (mobile-purchases-<stage>-user-subscriptions): This table records the link between a User (as defined by the Guardian) and a subscription.

These tables are exported daily to the datalake.

Architecture

See here.

Running TypeScript lambdas locally

We're using TypeScript to develop this project and it's useful to be able to test these locally, without having to resubmit a build and deploy to the cloud.

To avoid committing test data locally a test-launcher is provided to run a lambda locally, that will only read a file in a directory that's configured to not commit anything.

This can be run locally, and assumes a module with a function handler which takes some kind of a payload as a parameter.

Test a lambda locally by creating a payload json file under the mobile-purchases-payload directory and invoke the test-launcher with the name of your lambda module relative to the test-launcher along with the name of a payload file.

For example, to test the lambda that updates google subscriptions (typescript/update-subs/google.ts). This reads from an SQS queue, so create a a file sqs.json like this and put it in mobile-purchases-payload.

{
  "Records": [
    {
      "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
      "receiptHandle": "MessageReceiptHandle",
      "body": "{\"packageName\":\"not-saying\",\"purchaseToken\":\"idontwanttopushthistogithub",\"subscriptionId\":\"keeo-under-wraps\"}",
      "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "1523232000000",
        "SenderId": "123456789012",
        "ApproximateFirstReceiveTimestamp": "1523232000001"
      },
      "messageAttributes": {},
      "md5OfBody": "7b270e59b47ff90a553787216d55d91d",
      "eventSource": "aws:sqs",
      "eventSourceARN": "arn:aws:sqs:eu-west-1:123456789012:MyQueue",
      "awsRegion": "eu-west-1"
    }
  ]
}

This directory has its own .gitignore which means that any json files here remain local.

Invoke your function locally via the launcher script thus

yarn test-lambda update-subs/google sqs.json

mobile-purchases's People

Contributors

shtukas avatar dependabot[bot] avatar alexduf avatar jonflynng avatar frankie297 avatar nathanielbennett avatar markrichardsg avatar jacobwinch avatar tjmw avatar tomwadeson avatar jamieb-gu avatar dskamiotis avatar waisingyiu avatar michaelbjacobson avatar ecguardian avatar davidfurey avatar maelgnm avatar andrewheguardian avatar sarahjessica avatar umguardian avatar andreadiotallevi avatar marjisound avatar tomrf1 avatar paulbrown1982 avatar paulmr avatar jfsoul avatar kenoir avatar 01jonathanf avatar

Stargazers

Simon Haley avatar  avatar ze avatar Erik Slovák avatar  avatar Brandon Jones avatar  avatar Perttu avatar

Watchers

Aodh O Lionaird avatar theguardian.com continuous integration avatar James Cloos avatar  avatar George Haberis avatar Sam Morris avatar Anum Mian avatar Jon Hare-Winton avatar Richard Bangay avatar  avatar  avatar Natalia Baltazar avatar Prout avatar GuardianAndroid avatar  avatar Lucius Vorenus avatar  avatar Anna Beddow avatar  avatar  avatar

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.