Top Banner
Building Scalable Game Payment Systems HTML5 Gaming Payment Platforms Jonathan LeBlanc Developer Evangelist (PayPal) [email protected] Twitter: @jcleblanc Github: github.com/jcleblanc
33

HTML5 Gaming Payment Platforms

Jan 28, 2015

Download

Technology

While building a payment system into an ecommerce store may be a simple integration, creating those same payment solutions in the context of a cross-platform, real-time HTML5 game is a completely different story. In this talk we will explore how to integrate a real-time store experience into the context of an HTML5 game.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HTML5 Gaming Payment Platforms

Building Scalable Game Payment Systems

HTML5 Gaming Payment Platforms

Jonathan LeBlancDeveloper Evangelist (PayPal)

[email protected]: @jcleblanc

Github: github.com/jcleblanc

Page 2: HTML5 Gaming Payment Platforms

What are we going to talk about

Digital Payments

Cross Platform

Page 3: HTML5 Gaming Payment Platforms

Demo - JSWars

http://29a.ch/jswars/

Page 4: HTML5 Gaming Payment Platforms

The Architecture

The Implementation

The Product Webhooks

Session Breakdown

Page 5: HTML5 Gaming Payment Platforms

The Architecture

The Implementation

The Product Webhooks

Session Breakdown

Page 6: HTML5 Gaming Payment Platforms

The Players in our Little Game

Client & Server-Side Components

PayPal Digital Goods (Express Checkout)

HTML5 LocalStorage

jQuery

Page 7: HTML5 Gaming Payment Platforms

How Digital Goods Work

Fetch the token

Display login lightbox

Commit the payment

Verify the payment

Page 8: HTML5 Gaming Payment Platforms

Fetching Identity Information

Client Identity Server

PayPal Identity Server

Page 9: HTML5 Gaming Payment Platforms

Getting the Token and Lightbox

Client Requests Payment Token

PayPal Returns Token

Payment Lightbox Displayed to User

Page 10: HTML5 Gaming Payment Platforms

Within the Application

From Client Inventory Store

Fetching Inventory Information

Page 11: HTML5 Gaming Payment Platforms

Committing the Payment

Client Activates Success State

PayPal Returns Transaction Data

Client Approves Transaction

Page 12: HTML5 Gaming Payment Platforms

Store Identity Information

Store Transaction Information

Storing Data

Page 13: HTML5 Gaming Payment Platforms

Client Makes Verification Call to PayPal

PayPal Returns Purchase Data for User

Verifying the Purchase

Page 14: HTML5 Gaming Payment Platforms

Local Storage

Client Inventory System

Fetching LocalStorage Purchases

Page 15: HTML5 Gaming Payment Platforms

The Architecture

The Implementation

The Product Webhooks

Session Breakdown

Page 16: HTML5 Gaming Payment Platforms

Setup Sandbox User Accounts

https://developer.paypal.com/

Page 17: HTML5 Gaming Payment Platforms

Attach the script includes

Library & Toolkit Setup

<script src="https://www.paypalobjects.com/js/external/dg.js"></script>

<script src="client/jquery-min.js" type="text/javascript"></script>

Page 18: HTML5 Gaming Payment Platforms

Creating a Billing Handler

pptransact.bill({ userId:'[USER ID]', itemId:'[ITEM ID]', itemQty:'[ITEM QUANTITY]', successCallback: function(data){ //bill success }, failCallback: function(data){ //bill cancelled }});

Page 19: HTML5 Gaming Payment Platforms

How the Billing Flow Works

BillingRequest

Digital Goods

Bill

Success / Fail

ProductStorageStore Details

User Notificatio

nNotify User

Page 20: HTML5 Gaming Payment Platforms

Creating a Verification Handler

pptransact.verify({ userId:'[USER ID]', itemId:'[ITEM ID]', successCallback: function(data){ //verify success }, failCallback: function(data){ //verify failed }});

Page 21: HTML5 Gaming Payment Platforms

How the Verification Flow Works

VerificationRequest

ProductStorage

Get Data

Success / Fail

User Notificatio

nNotify User

Digital Goods

Verify Purchase

Success / Fail

Page 22: HTML5 Gaming Payment Platforms

Opening and Closing the Flow

Opening the Modal Window

Closing the Modal Window

var dgflow = dg.startFlow( 'https://www.sandbox.paypal.com/ webscr?&useraction=commit&token=###');

dgflow.closeFlow();

Page 23: HTML5 Gaming Payment Platforms

The Architecture

The Implementation

The Product Webhooks

Session Breakdown

Page 24: HTML5 Gaming Payment Platforms

Identity and Payment Hooks

Client Identity Server

PayPal Identity Server

Page 25: HTML5 Gaming Payment Platforms

Identity: verifyUser

function verifyUser($userId = 0){    $YourSessionUserId = '888888';        $returnVal = ($userId == $YourSessionUserId) ? true : false;    

return $returnVal;}

Page 26: HTML5 Gaming Payment Platforms

Identity: getUserId

function getUserId(){    $result = "888888";    return $result;}

Page 27: HTML5 Gaming Payment Platforms

Payment: recordPayment

function recordPayment($paymentObj = ""){    $userId = $paymentObj["userId"];    $itemId = $paymentObj["itemId"];    $transactionId = $paymentObj["transactionId"];    $paymentStatus = $paymentObj["paymentStatus"];    $orderTime = $paymentObj["orderTime"];            //INSERT YOUR CODE TO SAVE THE PAYMENT DATA}

Page 28: HTML5 Gaming Payment Platforms

Payment: verifyPayment

function verifyPayment($userId = 0, $itemId = 0){    $result = false;        //INSERT YOUR CODE TO QUERY PAYMENT DATA AND //RETURN TRUE if MATCH FOUND        return $result;}

Page 29: HTML5 Gaming Payment Platforms

Payment: getPayment

function getPayment($userId = 0, $itemId = 0){    //INSERT CODE TO QUERY AND RETURN PAYMENT STRUCTURE        $returnObj = array("success" => true,                       "error" => "",                       "transactionId" => "12345678",                       "orderTime" => "2011-09-29T04:47:51Z",                       "paymentStatus" => "Pending",                       "itemId" => "123",                       "userId" => "888888");        return $returnObj;}

Page 30: HTML5 Gaming Payment Platforms

Inventory Management Hooks

Client Inventory

Server

PayPal Digital Goods

Payment

Page 31: HTML5 Gaming Payment Platforms

Inventory: getItem

function getItem($itemId){    $items = array(        array(name => "Mega Shields",              number => "123",              qty => "1",              taxamt => "0",              amt => "1.00",              desc => "Unlock the power!",              category => "Digital"),        ...);        $returnObj = array();    for ($i = 0; $i < count($items); $i++){        if ($items[$i]['number'] == $itemId){            $returnObj = $items[$i];        }    }        return $returnObj;}

Page 32: HTML5 Gaming Payment Platforms

A Few Links

The HTML5 Toolkithttps://github.com/paypal/html5-dg

The PayPal Sandbox (Create Test Users)https://developer.paypal.com/

JSWars Code and Demo http://29a.ch/jswars/

Page 33: HTML5 Gaming Payment Platforms

Thank You! Any Questions?

http://www.slideshare.net/jcleblanc

Jonathan LeBlancDeveloper Evangelist (PayPal)

[email protected]: @jcleblanc

Github: github.com/jcleblanc