Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS Payments #946

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# template for auto-generated release notes
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes

changelog:
# exclude:
# labels:
# - ignore-for-release
# authors:
# - octocat
categories:
- title: ✨ Major Features
labels:
- epic
- title: 🪲 Bug Fixes
labels:
- bug
- cs
- title: 📱 Team Apps
labels:
- team_apps
- title: 📶 Team SDK
labels:
- team_sdk
- title: 🛠️ Team Infra
labels:
- team_infra
- telemetry
42 changes: 42 additions & 0 deletions .github/workflows/release-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release and Changelog

on:
workflow_dispatch:
push:
tags:
# a prerelease noted by a hyphen will not trigger
- 'lantern-[0-9]+.[0-9]+.[0-9]+'

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
# https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release
run: |
gh api -i \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases \
-f tag_name='${{ github.ref_name }}' \
-f name='Release ${{ github.ref_name }}' \
-f body='🤖 Autogenerated changelog for ${{ github.repository }} ${{ github.ref_name }}' \
-F draft=false \
-F prerelease=false \
-F generate_release_notes=true
- name: Strip repository name of owner
id: repo
run: |
echo "REPO_NAME=$(echo ${{ github.repository }} | sed s/'${{ github.repository_owner }}\/'//g)" >> "$GITHUB_OUTPUT"
- name: Trigger QC Checklist in customer-service repo
env:
GH_GRANTS_TOKEN: ${{ secrets.GH_GRANTS_TOKEN }}
run: |
echo "Sending QC Checklist trigger for ${{ steps.repo.outputs.REPO_NAME }} ${{ github.ref_name }}"
curl -i -H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token $GH_GRANTS_TOKEN" \
--request POST --data '{"event_type": "TRIGGER_QC_CHECKLIST", "client_payload": { "platform": "${{ steps.repo.outputs.REPO_NAME }}", "version": "${{ github.ref_name }}"}}' \
https://api.github.com/repos/getlantern/customer-support/dispatches
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public String getFormattedPrice(Map<String, Long> price) {
return getFormattedPrice(price, false);
}

private String getFormattedPrice(Map<String, Long> price, boolean formatFloat) {
private String getFormattedPrice(Map<String, Long> price, boolean formatFloat) {
final String formattedPrice;
Long currencyPrice = price.get(currencyCode);
if (currencyPrice == null) {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ replace github.com/google/netstack => github.com/getlantern/netstack v0.0.0-2022
replace github.com/eycorsican/go-tun2socks => github.com/getlantern/go-tun2socks v1.16.12-0.20201218023150-b68f09e5ae93

require (
github.com/bojanz/currency v1.1.3
github.com/getlantern/appdir v0.0.0-20200615192800-a0ef1968f4da
github.com/getlantern/autoupdate v0.0.0-20231030193554-30131726a6d9
github.com/getlantern/dnsgrab v0.0.0-20230822102054-7ff232ec3148
Expand Down Expand Up @@ -87,6 +88,7 @@ require (
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/siphash v1.2.3 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ github.com/bits-and-blooms/bitset v1.3.0 h1:h7mv5q31cthBTd7V4kLAZaIThj1e8vPGcSqp
github.com/bits-and-blooms/bitset v1.3.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bojanz/currency v1.1.3 h1:Ie8LYoMegQQlXH5Lq/gMRaWAD8J2/DYPewv+JV6UTPs=
github.com/bojanz/currency v1.1.3/go.mod h1:jNoZiJyRTqoU5DFoa+n+9lputxPUDa8Fz8BdDrW06Go=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/iter v0.0.0-20140124041915-454541ec3da2/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo=
github.com/bradfitz/iter v0.0.0-20190303215204-33e6a9893b0c/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo=
Expand All @@ -205,6 +207,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cloudfoundry/gosigar v1.1.0/go.mod h1:3qLfc2GlfmwOx2+ZDaRGH3Y9fwQ0sQeaAleo2GV5pH0=
github.com/cloudfoundry/gosigar v1.2.0/go.mod h1:3qLfc2GlfmwOx2+ZDaRGH3Y9fwQ0sQeaAleo2GV5pH0=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
github.com/colinmarc/hdfs/v2 v2.1.1/go.mod h1:M3x+k8UKKmxtFu++uAZ0OtDU8jR3jnaZIAc6yK4Ue0c=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -728,6 +732,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod h1:n931TsDuKuq+uX4v1fulaMbA/7ZLLhjc85h7chZGBCQ=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs=
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand Down
104 changes: 100 additions & 4 deletions internalsdk/apimodels/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ const (
baseUrl = "https://api.getiantem.org"
userDetailUrl = baseUrl + "/user-data"
userCreateUrl = baseUrl + "/user-create"
plansV3Url = baseUrl + "/plans-v3"
purchaseUrl = baseUrl + "/purchase"
)

const (
headerDeviceId = "X-Lantern-Device-Id"
headerUserId = "X-Lantern-User-Id"
headerProToken = "X-Lantern-Pro-Token"
headerContentType = "Content-Type"
)

var (
Expand All @@ -28,9 +37,9 @@ func FechUserDetail(deviceId string, userId string, token string) (*UserDetailRe
}

// Add headers
req.Header.Set("X-Lantern-Device-Id", deviceId)
req.Header.Set("X-Lantern-User-Id", userId)
req.Header.Set("X-Lantern-Pro-Token", token)
req.Header.Set(headerDeviceId, deviceId)
req.Header.Set(headerUserId, userId)
req.Header.Set(headerProToken, token)
log.Debugf("Headers set")

// Initialize a new http client
Expand Down Expand Up @@ -75,7 +84,7 @@ func UserCreate(deviceId string, local string) (*UserResponse, error) {
}

// Add headers
req.Header.Set("X-Lantern-Device-Id", deviceId)
req.Header.Set(headerDeviceId, deviceId)
log.Debugf("Headers set")
// Initialize a new http client
client := &http.Client{}
Expand All @@ -94,3 +103,90 @@ func UserCreate(deviceId string, local string) (*UserResponse, error) {
}
return &userResponse, nil
}

func PlansV3(deviceId string, userId string, local string, token string, countryCode string) (*PlansResponse, error) {
req, err := http.NewRequest("GET", plansV3Url, nil)
if err != nil {
log.Errorf("Error creating plans request: %v", err)
return nil, err
}
//Add query params
q := req.URL.Query()
q.Add("locale", local)
q.Add("countrycode", countryCode)
req.URL.RawQuery = q.Encode()

// Add headers
req.Header.Set(headerDeviceId, deviceId)
req.Header.Set(headerUserId, userId)
req.Header.Set(headerProToken, token)
log.Debugf("Plans Headers set")
// Initialize a new http client
client := &http.Client{}
// Send the request
resp, err := client.Do(req)
if err != nil {
log.Errorf("Error sending plans request: %v", err)
return nil, err
}

defer resp.Body.Close()

var plans PlansResponse
// Read and decode the response body
if err := json.NewDecoder(resp.Body).Decode(&plans); err != nil {
log.Errorf("Error decoding response body: %v", err)
return nil, err
}
return &plans, nil
}

func PurchaseRequest(data map[string]string, deviceId string, userId string, token string) (*PurchaseResponse, error) {
log.Debugf("purchase request body %v", data)
body, err := createJsonBody(data)
if err != nil {
log.Errorf("Error while creating json body")
return nil, err
}

log.Debugf("Encoded body %v", body)
// Create a new request
req, err := http.NewRequest("POST", purchaseUrl, body)
if err != nil {
log.Errorf("Error creating new request: %v", err)
return nil, err
}

// Add headers
req.Header.Set(headerDeviceId, deviceId)
req.Header.Set(headerUserId, userId)
req.Header.Set(headerProToken, token)
req.Header.Set(headerContentType, "application/json")

client := &http.Client{}
// Send the request
resp, err := client.Do(req)
if err != nil {
log.Errorf("Error sending puchase request: %v", err)
return nil, err
}

defer resp.Body.Close()

var purchase PurchaseResponse
// Read and decode the response body
if err := json.NewDecoder(resp.Body).Decode(&purchase); err != nil {
log.Errorf("Error decoding response body: %v", err)
return nil, err
}
return &purchase, nil
}

// Utils methods convert json body
func createJsonBody(data map[string]string) (*bytes.Buffer, error) {
jsonData, err := json.Marshal(data)
if err != nil {
return nil, err
}
return bytes.NewBuffer(jsonData), nil
}
72 changes: 72 additions & 0 deletions internalsdk/apimodels/json_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,75 @@ type UserDevice struct {
Name string `json:"name"`
Created int64 `json:"created"`
}

// Plans Json struct

type PlansResponse struct {
Plans []Plan `json:"plans"`
Providers Providers `json:"providers"`
}

type Plan struct {
ID string `json:"id"`
Description string `json:"description"`
Duration Duration `json:"duration"`
Price map[string]int64 `json:"price"`
ExpectedMonthlyPrice map[string]int64 `json:"expectedMonthlyPrice"`
UsdPrice int64 `json:"usdPrice"`
UsdPrice1Y int64 `json:"usdPrice1Y"`
UsdPrice2Y int64 `json:"usdPrice2Y"`
RedeemFor RedeemFor `json:"redeemFor"`
RenewalBonus RedeemFor `json:"renewalBonus"`
RenewalBonusExpired RedeemFor `json:"renewalBonusExpired"`
RenewalBonusExpected RedeemFor `json:"renewalBonusExpected"`
Discount float64 `json:"discount"`
BestValue bool `json:"bestValue"`
Level string `json:"level"`
TotalCostBilledOneTime string
FormattedDiscount string
FormattedBonus string
OneMonthCost string
TotalCost string
}

type Price struct {
Usd int64 `json:"usd"`
}

type Duration struct {
Days int64 `json:"days"`
Months int64 `json:"months"`
Years int64 `json:"years"`
}

type RedeemFor struct {
Days int64 `json:"days"`
Months int64 `json:"months"`
}

type Providers struct {
Android []Android `json:"android"`
Desktop []Android `json:"desktop"`
}

type Android struct {
Method string `json:"method"`
Providers []Provider `json:"providers"`
}

type Provider struct {
Name string `json:"name"`
Data *Data `json:"data,omitempty"`
}

type Data struct {
PubKey string `json:"pubKey"`
}

//Purchase Request

type PurchaseResponse struct {
PaymentStatus string `json:"paymentStatus"`
Plan Plan `json:"plan"`
Status string `json:"status"`
}
Loading
Loading