npm i --save nativescript-plugin-square-pos
- 版本:1.0.0
- GitHub: https://github.com/okidoo/nativescript-square-pos
- NPM: https://npmjs.net.cn/package/nativescript-plugin-square-pos
- 下载
- 昨天: 0
- 上周: 0
- 上个月: 0
NativeScript Square POS
此插件允许您通过 Square POS 应用从您的移动应用程序接受 Square 支付。这是使用仅限于少数国家的 Square API 的替代方案。目前,仅实现了 Android,并且演示仅适用于 Angular,欢迎您的贡献。
先决条件 / 要求
您只需注册您的应用程序,因为 Square POS 需要验证请求的来源。
安装
tns plugin add nativescript-square-pos
演示用法
在 ./demo-angular 文件夹中
Android
tns debug android
在 Angular 中的使用
// test.component.ts
import {
SquarePos,
SquareChargeEventData,
SquareCurrencies,
} from "nativescript-square-pos";
@Component({
selector: "Test",
templateUrl: "./test.component.html",
})
export class AppComponent {
public currency: SquareCurrencies = "CAD";
public applicationId: string = "YOUR_SQUARE_APPLICATION_ID";
public squarePos: SquarePos = new SquarePos(this.applicationId);
public result: string = "";
public isAppInstalled: boolean;
constructor(private ngZone: NgZone) {
// Add event listeners for transactions
this.ngZone.run(() => {
this.squarePos.on(
"squareChargeUnknownError",
this.onSquareChargeUnknownError,
this
);
this.squarePos.on(
"squareChargeSuccess",
this.onSquareChargeSuccess,
this
);
this.squarePos.on(
"squareChargeError",
this.onSquareChargeError,
this
);
});
this.isAppInstalled = this.squarePos.isAppInstalled();
}
public onTransaction(amount: number): void {
try {
this.squarePos.startTransaction(amount, this.currency);
} catch (e) {
this.result = "An error occured while launching Square Point of Sale app.";
}
}
public onAppInstall(): void {
this.squarePos.openAppInstallation();
const onResume = (args) => {
this.isAppInstalled = this.squarePos.isAppInstalled();
app.off(app.resumeEvent, onResume);
};
app.on(app.resumeEvent, onResume);
}
private onSquareChargeUnknownError(data: SquareChargeEventData) {
this.ngZone.run(() => {
this.result = "An unknown error occured. Square Point of Sale was uninstalled or stopped working.";
});
}
private onSquareChargeSuccess(data: SquareChargeEventData) {
this.ngZone.run(() => {
this.result = `Transaction ${data.object.success.clientTransactionId} was successfully completed.`;
});
}
private onSquareChargeError(data: SquareChargeEventData) {
this.ngZone.run(() => {
this.result = `The transaction was not completed. The error was ${data.object.error.code}: ${data.object.error.debugDescription}.`;
});
}
}
许可证
MIT (请参阅许可证文件)