Skip to content
Merged
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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const trolley = require('trolley');
const client = trolley.connect({
key: "YOUR-API-KEY",
secret: "YOUR-API-SECRET",
environment: "production",
});

// Async/Await version
Expand Down Expand Up @@ -67,7 +66,6 @@ If you're working on the library itself, here's easy way to run the tests.
$ cp .env.test .env

// Set access key and secret in the env file
TROLLEY_ENVIRONMENT="production"
TROLLEY_ACCESS_KEY="ACCESS_KEY"
TROLLEY_SECRET_KEY="SECRET_KEY"

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

Create a client for the Trolley (Payment Rails) JavasScript API

const client = paymentrails.connect({
const client = trolley.connect({
key: "MY_PUBLIC_KEY",
secret: "MY_PRIVATE_KEY",
});
Expand Down
44 changes: 6 additions & 38 deletions lib/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Gateway } from "./Gateway";

export interface ConfigurationParams {
/**
* The Trolley public key
* The Trolley access key
*/
key: string;
/**
* The Trolley private key
* The Trolley secret key
*/
secret: string;
/**
* The environment that you're using, most likely one of "production" or "sandbox"
* Optional. The base URL to use to connect to the API gateway. Useful while running from source.
*/
environment?: "production" | "sandbox" | "integration" | "development";
apiBase?: string;
}

// tslint:disable:function-name
Expand Down Expand Up @@ -40,13 +40,8 @@ export class Configuration {
*/
constructor(config?: ConfigurationParams) {
this.apiKey = (config && config.key) || Configuration.apiKeyDefault;
this.apiSecret =
(config && config.secret) || Configuration.apiSecretDefault;
if (config && config.environment) {
this.apiBase = Configuration.environmentToUrl(config.environment);
} else {
this.apiBase = Configuration.apiBaseDefault;
}
this.apiSecret = (config && config.secret) || Configuration.apiSecretDefault;
this.apiBase = (config && config.apiBase) || Configuration.apiBaseDefault;
}

/**
Expand Down Expand Up @@ -83,31 +78,4 @@ export class Configuration {
static setApiBase(baseUrl: string) {
Configuration.apiBaseDefault = baseUrl;
}

/**
* Set the Trolley API environment that your using
* @param environment one of "production" or "sandbox"
*/
static setEnvironment(environment: "production" | "sandbox" | "integration") {
Configuration.apiBaseDefault = Configuration.environmentToUrl(environment);
}

/**
* Private method that converts an environment to a specific URL
* @param environment "production" | "sandbox"
* @hidden
*/
private static environmentToUrl(environment: string) {
switch (environment) {
case "integration":
// tslint:disable-next-line:no-http-string
return "http://api.local.dev:3000";
case "sandbox":
return "https://api.trolley.com";
case "production":
return "https://api.trolley.com";
default:
return "https://api.trolley.com";
}
}
}
1 change: 0 additions & 1 deletion test/integration/helpers/integrationTestsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as nock from "nock";
export const testingApiClient = trolley.connect({
key: process.env.TROLLEY_ACCESS_KEY,
secret: process.env.TROLLEY_SECRET_KEY,
environment: process.env.TROLLEY_ENVIRONMENT as any,
} as any);

export let nockBack = nock.back
Expand Down