iPag SDK for Node.js
A ferramenta certa para efetuar a sua integração de forma rápida e segura com os serviços iPag.
Este projeto foi convertido do iPag SDK for PHP usando o Google Gemini.
Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades disponíveis na API do iPag. Veja a documentação completa da API em https://developers.ipag.com.br/.
Execute em seu shell:
npm install ipag-sdk-node
Classe responsável pela integração com a API do iPag. Através dela você consegue acessar todos os endpoints disponíveis na API.
Para mais informações de como funciona a autenticação no Ipag, consulte: Autenticação Ipag
const { IpagClient, IpagEnvironment } = require('ipag-sdk-node');
const ipagClient = new IpagClient(
'apiID',
'apiKey',
IpagEnvironment.SANDBOX
);const { PaymentTransaction, PaymentTypes, Cards } = require('ipag-sdk-node');
const paymentTransaction = new PaymentTransaction({
amount: 100,
callback_url: 'https://ipag-sdk.requestcatcher.com/callback',
order_id: '12345679',
payment: {
type: PaymentTypes.CARD,
method: Cards.VISA,
installments: 4,
card: {
holder: 'Bruce Wayne',
number: '4111111111111111',
expiry_month: '01',
expiry_year: '2025',
cvv: '123'
}
},
customer: {
name: 'Bruce Wayne',
cpf_cnpj: '490.558.550-30'
}
});
ipagClient.payment().create(paymentTransaction)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { Token } = require('ipag-sdk-node');
const token = new Token({
card: {
holderName: 'Bruce Wayne',
number: '4111111111111111',
expiryMonth: '01',
expiryYear: '2025',
cvv: '123'
},
holder: {
name: 'Bruce Wayne',
cpfCnpj: '490.558.550-30',
mobilePhone: '(22) 2222-33333',
birthdate: '1987-02-19',
address: {
street: 'Avenida Principal',
number: '12345',
complement: 'Sala 02',
district: 'São Paulo',
city: 'São Paulo',
state: 'SP',
zipcode: '01310-000'
}
}
});
ipagClient.token().create(token)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { PaymentTransaction, PaymentTypes, Cards } = require('ipag-sdk-node');
const paymentTransaction = new PaymentTransaction({
amount: 0,
callback_url: 'https://ipag-sdk.requestcatcher.com/callback',
order_id: '12345679',
payment: {
type: PaymentTypes.CARD,
method: Cards.VISA,
installments: 1,
card: {
holder: 'Bruce Wayne',
number: '4111111111111111',
expiry_month: '01',
expiry_year: '2025',
cvv: '123'
}
},
customer: {
name: 'Bruce Wayne',
cpf_cnpj: '490.558.550-30'
}
});
ipagClient.payment().create(paymentTransaction)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { PaymentTransaction, PaymentTypes, Cards } = require('ipag-sdk-node');
const paymentTransaction = new PaymentTransaction({
amount: 100,
callback_url: 'https://ipag-sdk.requestcatcher.com/callback',
order_id: '12345679',
payment: {
type: PaymentTypes.CARD,
method: Cards.VISA,
installments: 1,
card: {
holder: 'Bruce Wayne',
number: '4111111111111111',
expiry_month: '01',
expiry_year: '2025',
cvv: '123'
}
},
customer: {
name: 'Bruce Wayne',
cpf_cnpj: '490.558.550-30'
}
});
ipagClient.payment().create(paymentTransaction)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { PaymentTransaction, PaymentTypes, Cards } = require('ipag-sdk-node');
const paymentTransaction = new PaymentTransaction({
amount: 100,
callback_url: 'https://ipag-sdk.requestcatcher.com/callback',
order_id: '12345679',
payment: {
type: PaymentTypes.CARD,
method: Cards.VISA,
installments: 1,
card: {
token: 'TOKEN_DO_CARTAO'
}
},
customer: {
name: 'Bruce Wayne',
cpf_cnpj: '490.558.550-30'
}
});
ipagClient.payment().create(paymentTransaction)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { PaymentTransaction, PaymentTypes, Cards } = require('ipag-sdk-node');
const paymentTransaction = new PaymentTransaction({
amount: 100,
callback_url: 'https://ipag-sdk.requestcatcher.com/callback',
order_id: '12345679',
payment: {
type: PaymentTypes.CARD,
method: Cards.VISA,
installments: 1,
card: {
holder: 'Bruce Wayne',
number: '4111111111111111',
expiry_month: '01',
expiry_year: '2025',
cvv: '123',
tokenize: true
}
},
customer: {
name: 'Bruce Wayne',
cpf_cnpj: '490.558.550-30'
}
});
ipagClient.payment().create(paymentTransaction)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { SubscriptionPlan, Interval } = require('ipag-sdk-node');
const subscriptionPlan = new SubscriptionPlan({
name: 'Plano de Assinatura',
amount: 100,
interval: Interval.MONTHLY,
frequency: 1,
trial_period: 30
});
ipagClient.subscriptionPlan().create(subscriptionPlan)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});const { Subscription } = require('ipag-sdk-node');
const subscription = new Subscription({
plan_id: 'ID_DO_PLANO',
customer: {
name: 'Bruce Wayne',
cpf_cnpj: '490.558.550-30'
},
card: {
token: 'TOKEN_DO_CARTAO'
}
});
ipagClient.subscription().create(subscription)
.then(response => {
console.log(response.getData());
})
.catch(error => {
console.log(error.getCode());
console.log(error.getErrors());
});Em caso de dúvida ou sugestão para o SDK abra uma nova Issue.