Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@canyaio/canpay-lib
Advanced tools
Angular component for accepting payments in CAN through a seamless user experience using an a configurable params, See how does it work.
Accepting payment with token in any dApp can be cumbersome because a developer needs to do mulitple checks and transactions in order to finalize a payment and same applies for the CanYaCoin (CAN).
To streamline the process, we've created a component that takes care of the following:
Component is packed in an npm package and can be used as normal angular module.
npm i @canyaio/canpay-lib
/assets/img
folder.In your module file:
import { CanpayModule } from 'canpay-lib';
// include the module in your imported modules with (optional) configuration object
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
CanpayModule.forRoot({
useTestNet: <TRUE_FALSE>,
contracts: {
canyaCoinAddress: <CanYaCoin_ADDRESS>,
canyaAbi: <CanYaCoin_ABI> // optional, default is set the prod CanYaCoin ABI
}
})
],
providers: [],
bootstrap: [AppComponent],
})
// In your controller file, define an object with the following params
canPay = {
dAppName: 'CANWork',
recipient: <CANWORK_CONTRACT_ADDRESS>,
amount: <AMOUNT_IN_CAN>,
complete: <CALLBACK_ON_SUCCESS>,
cancel: <CALLBACK_ON_CANCEL>
}
<!-- In your template file -->
<canyalib-canpay
[dAppName]="canPay.dAppName"
[successText]="canPay.successText"
[recipient]="canPay.recipient"
[amount]="canPay.amount"
(complete)="canPay.complete($event)"
(cancel)="canPay.cancel($event)"
></canyalib-canpay>
Nothing to be defiend in the template file, only in the controller file.
// In your controller file, define an object with the following params
canPay = {
dAppName: 'CANWork',
recipient: <CANWORK_CONTRACT_ADDRESS>,
amount: <AMOUNT_IN_CAN>,
complete: <CALLBACK_ON_SUCCESS>,
cancel: <CALLBACK_ON_CANCEL>
}
constructor(private canPayService: CanPayService) { }
open() {
this.canPayService.open(this.canPay);
}
onCancel(){
this.canPayService.close();
}
Here is a list of the full list of peroperties to configure the CANPay component.
Property | Description |
---|---|
dAppName | Name of the dApp to be displayed to the user as a merchant name. |
onAuthTxHash | Function to execute once the hash of the transaction is returned from the authorisation operation. |
onPaymentTxHash | Function to execute once the hash of the transaction is returned from the payment operation. |
recipient | The dApp contract address that will receive the payment |
amount | Optional If set, no amount-input-box will be displayed to the user and the specified amount will be forced. |
paymentSummary | Optional If set, will show a nice payment summary screen of the transaction, if not set, uses amount. |
minAmount | Optional If amount is set, this will be the minum accepted amount from the user. |
maxAmount | Optional If amount is set, this will be the maximum accepted amount from the user. |
complete | Callback to be triggered upon successful completion of the whole wizard steps. Input: CanPayData |
cancel | Callback to be triggered if the user cancelled the wizard. Input: CanPayData |
postAuthorisationProcessName | Optional Action name to be exexuted after payment authorisation, Ex: 'Task Deposit'. |
startPostAuthorisationProcess | Optional callback to be triggered after a user authorisation for the requested amount. It's used to allow a developer to execute external/extended payment operation from the CanYaCoin contract to the dApp contract. Input: CanPayData |
postAuthorisationProcessResults | Optional if postAuthorisationProcessName is set. It's used to notify the wizard of the success or failure of the postAuthorisationProcess. |
destinationAddress | It is the destination address of the user where the CANS will be transferred. |
disableCanEx | Should CanExchange be enabled for the purchasing of CAN (default true) |
userEmail | Email address to send canexchange verification email |
interface CanPay {
dAppName: string;
operation?: Operation;
onAuthTxHash? : Function;
recipient: string;
amount?: number;
paymentSummary?: PaymentSummary;
minAmount?: number;
maxAmount?: number;
postAuthorisationProcessName?: string;
postAuthorisationProcessResults?: ProcessActionResult;
canyaContract?: Contract;
startPostAuthorisationProcess?: Function;
complete: Function;
cancel?: Function;
currentStep?: Function;
disableCanEx? : boolean;
destinationAddress?: string;
userEmail?: string;
}
The following are the enum for full wizard steps:
enum Step {
metamask = 0,
paymentAmount = 1,
balanceCheck = 2,
buyCan = 3,
authorisation = 4,
payment = 5,
process = 6,
confirmation = 7,
completed = 8,
details = 9,
staging = 10,
erc20 = 11,
complete = 12,
qr = 13,
error = 14
}
Type of CanPay operations, default is Authorise.
enum Operation {
auth = 'Authorise', // Request user authoisation to withdraw CAN
pay = 'Pay' // Request user to pay CAN directly to the specified recipient
interact = 'Interact' // Go straight to the post auth process
}
A message to notify CANPay with the postAuthorisationProcess execution results.
interface ProcessActionResult {
type: ProcessAction; // { success = 0, error = 1 }
msg: string; // in case of an error, optional error message to be specified
}
Data passed to the callback functions (complete, cancel and startPostAuthorisationProcess)
Property | Description |
---|---|
amount | Amount specified by either the developer or entered by the user |
account | User eth address |
balance | User CAN balance |
step | Current wizard Step |
Customize the wizard UI to fit in small areas
enum View {
Normal, // default
Compact
}
A utility function that sets the postAuthorisationProcessResults
based on the passed in transaction param. See usage example
function setProcessResult(txOrErr) {
this.postAuthorisationProcessResults = {
type: !txOrErr.status ? ProcessAction.error : ProcessAction.success,
msg: !txOrErr.status ? (txOrErr.message || 'Transaction failed') : null
};
}
The CanPayExample is a fully working example on how to use the CanPay with postAuthorisationProcess params.
git clone git@github.com:canyaio/Common.git && cd Common && git checkout lib/canpay && npm i
ganache-cli --port 9545
npm run init-deploy-contracts
zos.local.json
under ./src/
directorynpm run build_lib && npm start
FAQs
README.md
We found that @canyaio/canpay-lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.