mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-17 00:51:07 +08:00
feat(sum-up): add plugin (#3080)
This commit is contained in:
parent
54ac2bfdf5
commit
a4db080786
192
src/@ionic-native/plugins/sum-up/index.ts
Normal file
192
src/@ionic-native/plugins/sum-up/index.ts
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
|
||||||
|
|
||||||
|
export interface SumUpResponse {
|
||||||
|
// Code to identify the message
|
||||||
|
code: number;
|
||||||
|
|
||||||
|
// Message for readable usage
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SumUpLoginStatus {
|
||||||
|
// Code, to check if an error occured
|
||||||
|
code: number;
|
||||||
|
|
||||||
|
// Booleand value whether the user is logged in or not
|
||||||
|
isLoggedIn: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SumUpPayment {
|
||||||
|
// Unique transaction code
|
||||||
|
transaction_code: string;
|
||||||
|
|
||||||
|
// Card type -> like MAESTRO
|
||||||
|
card_type: string;
|
||||||
|
|
||||||
|
// Merchant code for identification
|
||||||
|
merchant_code: string;
|
||||||
|
|
||||||
|
// Amount of the payment
|
||||||
|
amount: number;
|
||||||
|
|
||||||
|
// Tip amount -> default 0
|
||||||
|
tip_amount: number;
|
||||||
|
|
||||||
|
// Vat amount -> default 0
|
||||||
|
vat_amount: number;
|
||||||
|
|
||||||
|
// Currency code -> like EUR
|
||||||
|
currency: string;
|
||||||
|
|
||||||
|
// Payment status -> successful or error
|
||||||
|
status: string;
|
||||||
|
|
||||||
|
// Type -> Card or nfc
|
||||||
|
payment_type: string;
|
||||||
|
|
||||||
|
// Entry mode -> Like chip or contactless
|
||||||
|
entry_mode: string;
|
||||||
|
|
||||||
|
// Number of installments -> default 1
|
||||||
|
installments: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name SumUp
|
||||||
|
* @description
|
||||||
|
* Plugin to communicate with a SumUp payment terminal
|
||||||
|
*
|
||||||
|
* @usage
|
||||||
|
* ```typescript
|
||||||
|
* import { SumUp } from '@ionic-native/sum-up';
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* constructor(private sumUp: SumUp) { }
|
||||||
|
*
|
||||||
|
* this.sumUp.login("ACCESS_TOKEN")
|
||||||
|
* .then((res: SumUpResponse) => console.log(res))
|
||||||
|
* .catch((error: SumUpResponse) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.auth("ACCESS_TOKEN")
|
||||||
|
* .then((res: SumUpResponse) => console.log(res))
|
||||||
|
* .catch((error: SumUpResponse) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.getSettings()
|
||||||
|
* .then((res: SumUpResponse) => console.log(res))
|
||||||
|
* .catch((error: SumUpResponse) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.logout()
|
||||||
|
* .then((res: SumUpResponse) => console.log(res))
|
||||||
|
* .catch((error: SumUpResponse) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.isLoggedIn()
|
||||||
|
* .then((res: SumUpLoginStatus) => console.log(res))
|
||||||
|
* .catch((error: SumUpLoginStatus) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.prepare()
|
||||||
|
* .then((res: SumUpResponse) => console.log(res))
|
||||||
|
* .catch((error: SumUpResponse) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.closeConnection()
|
||||||
|
* .then((res: SumUpResponse) => console.log(res))
|
||||||
|
* .catch((error: SumUpResponse) => console.error(error));
|
||||||
|
*
|
||||||
|
* this.sumUp.pay(10.0, "EUR")
|
||||||
|
* .then((res: SumUpPayment) => console.log(res))
|
||||||
|
* .catch((error: SumUpPayment) => console.error(error));
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
@Plugin({
|
||||||
|
pluginName: 'SumUp',
|
||||||
|
plugin: 'cordova-sumup-plugin',
|
||||||
|
pluginRef: 'window.SumUp',
|
||||||
|
repo: 'https://github.com/mariusbackes/cordova-plugin-sumup',
|
||||||
|
install:
|
||||||
|
'cordova plugin add cordova-sumup-plugin --variable SUMUP_API_KEY=INSERT_YOUR_KEY',
|
||||||
|
installVariables: ['SUMUP_API_KEY'],
|
||||||
|
platforms: ['Android', 'iOS']
|
||||||
|
})
|
||||||
|
@Injectable()
|
||||||
|
export class SumUp extends IonicNativePlugin {
|
||||||
|
/**
|
||||||
|
* Login a user with an optional access token.
|
||||||
|
* If the access token is provided and valid, the user is logged in autmatically.
|
||||||
|
* Otherwise the user has to type in the credentials
|
||||||
|
* @param accessToken {string}
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
login(accessToken?: string): Promise<SumUpResponse> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authenticates the account with the given access token. Parameter accessToken is required.
|
||||||
|
* @param accessToken {string}
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
auth(accessToken: string): Promise<SumUpResponse> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a new window with the all account settings of an logged in user.
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
getSettings(): Promise<SumUpResponse> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logout a user from the account.
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
logout(): Promise<SumUpResponse> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the user is logged in or not and returns an object with the field isLoggedIn which is a boolean value.
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
isLoggedIn(): Promise<SumUpLoginStatus> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares the terminal for a payment. Checks whether the CardReader is ready to transmit and
|
||||||
|
* if an instance of the CardReaderManager is available.
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
prepare(): Promise<SumUpResponse> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to close the connection to the card terminal.
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
closeConnection(): Promise<SumUpResponse> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a native SumUp window to proceed a payment. Parameter amount and currencycode are required.
|
||||||
|
* If the Payment was successful it returns an SumUpPayment object with information about the payment.
|
||||||
|
* @param amount {number}
|
||||||
|
* @param currencycode {string}
|
||||||
|
* @return {Promise<SumUpResponse>} Return a SumUpResponse object
|
||||||
|
*/
|
||||||
|
@Cordova()
|
||||||
|
pay(amount: number, currencycode: string): Promise<SumUpPayment> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user