· 4 years ago · Apr 28, 2021, 01:40 AM
1<?php
2//// VARIABLES
3// base URL for Octobat Beanie
4$beanieHostBase = 'https://beanie.octobat.com/checkout/';
5// Publishable key, get from Octobat Beanie Dashboard
6$octobatPublishableKey = 'YOUR_OCTOBAT_BEANIE_PUBLISHABLE_KEY';
7// Session ID, get by requesting from Octobat API, see:
8// https://docs.octobat.com/octobat/beanie/collecting-payments/beanie-client-server#create-a-beaniesession-on-the-server
9$sessionId = 'THE_OCTOBAT_BEANIE_SESSION_ID_FOR_THIS_CHECKOUT_PAGE';
10
11// Get the Beanie checkout page URL and redirect to it
12$beanieURL = returnBeanieURL($octobatPublishableKey, $beanieHostBase, $sessionId);
13header('Location: ' . $beanieURL, 301);
14exit;
15
16//// FUNCTIONS
17function returnBeanieURL($octobatPublishableKey, $beanieHostBase, $sessionId){
18 return $beanieHostBase . encodeURIComponent($sessionId) . "#" . encodeJsonParams( json_encode(array('apiKey' => $octobatPublishableKey)) );
19}
20
21function myS($e){
22 $t = 3 - strlen($e) % 3;
23 return "" . $e . implode(" ", array_fill(0, $t + 1, ''));
24}
25
26function myX($e){
27 $t = "";
28 for($r = 0; $r < strlen($e); ++$r)
29 $t .= chr(5 ^ ord($e[$r]));
30 return $t;
31}
32
33function encodeURIComponent($e) {
34 return rawurlencode($e);
35}
36
37function encodeJsonParams($e){
38 return encodeURIComponent(base64_encode(myX(myS($e))));
39}
40