https://github.com/jaimerc/payment-gateways-module
https://github.com/jaimerc/payment-gateways-module
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jaimerc/payment-gateways-module
- Owner: JaimeRC
- Created: 2020-02-04T21:48:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-07T22:44:43.000Z (about 3 years ago)
- Last Synced: 2025-11-16T19:06:13.150Z (8 months ago)
- Language: JavaScript
- Size: 256 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Payment Gateway Module
## Paypal
### Flujo
1.- Construir la conexion con PayPal (Server)
var gateway = braintree.connect({
accessToken: useYourAccessToken
});
`useYourAccessToken` es el Token de la agencia que se registra en PayPal.
2.- Generaramos el ClienToken para que el cliente pueda realizar la transaccion con PayPal. (Server)
const clientToken = await gateway.clientToken.generate({});
3.- Se genera el botón para realizar la Autorización con PayPal, incluyendo el Token y la información del pago para que se muestre la pantalla de Autorización de PayPal y pueda confirmar la operación. (Client)
paypal.Button.render({
braintree: braintree, // Modulo de NPM
client: {
production: 'CLIENT_TOKEN_FROM_SERVER', // Token para producción
sandbox: 'CLIENT_TOKEN_FROM_SERVER' // Token para realizar Test
},
env: 'production', // Elegir el entorno (production o sandbox)
commit: true, // Esto agregara el importe al boton de PayPal
payment: function (data, actions) {
return actions.braintree.create({
flow: 'checkout', // Tipo de Flow
amount: 10.00, // Importe de la operación
currency: 'USD', // Moneda
enableShippingAddress: true, // Habilitar datos de envio
shippingAddressEditable: false, // habilitar edición de los datos de envio
shippingAddressOverride: { //Datos de envío
recipientName: 'Scruff McGruff',
line1: '1234 Main St.',
line2: 'Unit 1',
city: 'Chicago',
countryCode: 'US',
postalCode: '60652',
state: 'IL',
phone: '123.456.7890'
}
});
},
onAuthorize: function (payload) {
// Si se ha autorizado nos devuelve un token `payload.nonce` para enviar al Servidor y finalizar la transacción
},
}, '#paypal-button');
4.- Con el `nonce` recibido se realiza una peticion a PayPal para que se realice el abono a la cuenta de la agencia.
var saleRequest = {
amount: req.body.amount,
merchantAccountId: "USD",
paymentMethodNonce: req.body.nonce,
orderId: "Mapped to PayPal Invoice Number",
descriptor: {
name: "Descriptor displayed in customer CC statements. 22 char max"
},
shipping: {
firstName: "Jen",
lastName: "Smith",
company: "Braintree",
streetAddress: "1 E 1st St",
extendedAddress: "5th Floor",
locality: "Bartlett",
region: "IL",
postalCode: "60103",
countryCodeAlpha2: "US"
},
options: {
paypal: {
customField: "PayPal custom field",
description: "Description for PayPal email receipt"
},
submitForSettlement: true
}
};
const {success , transaction } = await gateway.transaction.sale
if (!success)
throw Error('Error in transaction.')
transaction.status // "authorized"
transaction.id
### Flujo del Cliente

### Flujo del Servidor
