This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from remedyproduct/development
Development
- Loading branch information
Showing
9 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Build and deploy | ||
on: | ||
push: | ||
branches: | ||
- "*" | ||
- "!master" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
env: | ||
NODE_VERSION: 14 | ||
steps: | ||
- name: Сheckout repo | ||
uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ env.NODE_VERSION }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
- name: Cache node modules | ||
uses: actions/cache@v1 | ||
env: | ||
cache-name: cache-node-modules | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}- | ||
${{ runner.os }}-build- | ||
${{ runner.os }}- | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run linter | ||
run: npm run lint | ||
- name: Run builder | ||
run: npm run build | ||
- name: Run test | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Card } from "@stripe/stripe-js"; | ||
import { responseHandler } from "../utils/handlers"; | ||
import { stripeApiUrl, stripeApiVersion } from "../utils/constants"; | ||
import { getApiKey } from "../utils/store"; | ||
|
||
/** | ||
* Add payment method to customer (from source or token). | ||
* | ||
* @param source - source or token string (see: https://stripe.com/docs/api/sources/object) | ||
* @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id) | ||
* @param customerEphemeralKey - customer ephemeral key | ||
* @returns | ||
*/ | ||
export const addSourceToCustomer = async ( | ||
token: string, | ||
customerId: string, | ||
customerEphemeralKey: string | ||
): Promise<Card | undefined> => { | ||
const stripeApiKey = getApiKey() as string; | ||
if (typeof stripeApiKey !== "string") | ||
throw new Error("Initialization failed."); | ||
|
||
// make request | ||
return fetch(`${stripeApiUrl}/customers/${customerId}/sources`, { | ||
body: `source=${token}`, | ||
headers: { | ||
Authorization: `Bearer ${customerEphemeralKey}`, | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"Stripe-Version": `${stripeApiVersion}`, | ||
}, | ||
method: "POST", | ||
}).then(responseHandler); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Card } from "@stripe/stripe-js"; | ||
import { responseHandler } from "../utils/handlers"; | ||
import { stripeApiUrl, stripeApiVersion } from "../utils/constants"; | ||
import { getApiKey } from "../utils/store"; | ||
|
||
/** | ||
* Delete payment method from customer. | ||
* | ||
* @param sourceId - source or card id (see: https://stripe.com/docs/api/sources/object#source_object-id) | ||
* @param customerId - customer id (see: https://stripe.com/docs/api/customers/object#customer_object-id) | ||
* @param customerEphemeralKey - customer ephemeral key | ||
* @returns | ||
*/ | ||
export const deleteSourceFromCustomer = async ( | ||
sourceId: string, | ||
customerId: string, | ||
customerEphemeralKey: string | ||
): Promise<Card | undefined> => { | ||
const stripeApiKey = getApiKey() as string; | ||
if (typeof stripeApiKey !== "string") | ||
throw new Error("Initialization failed."); | ||
|
||
// make request | ||
return await fetch( | ||
`${stripeApiUrl}/customers/${customerId}/sources/${sourceId}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${customerEphemeralKey}`, | ||
"Stripe-Version": stripeApiVersion, | ||
}, | ||
method: "DELETE", | ||
} | ||
).then(responseHandler); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { confirmPaymentIntentByCard } from "./confirmPaymentIntentByCard"; | ||
import { addSourceToCustomer } from "./addSourceToCustomer"; | ||
import { deleteSourceFromCustomer } from "./deleteSourceFromCustomer"; | ||
|
||
/** | ||
* additional stripe methods | ||
*/ | ||
export class additionalMethods { | ||
public confirmPaymentIntentByCard = confirmPaymentIntentByCard; | ||
public addSourceToCustomer = addSourceToCustomer; | ||
public deleteSourceFromCustomer = deleteSourceFromCustomer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const stripeApiUrl = "https://api.stripe.com"; | ||
export const stripeApiUrl = "https://api.stripe.com/v1"; | ||
export const stripeApiVersion = "2020-08-27"; |