src/app/components/pays/pays.component.ts
Renderiza el botón de Paypal para efectuar el pago por dicho medio.
selector | app-pays |
styleUrls | ../home/home.component.css |
templateUrl | ./pays.component.html |
Properties |
Methods |
constructor(router: Router, answers: AnswersService, rates: RatesService, auth: AuthenticationService, http: HttpClient, toastr: ToastrService)
|
|||||||||||||||||||||
Defined in src/app/components/pays/pays.component.ts:41
|
|||||||||||||||||||||
Constructor - Se obtiene la respuesta actualmente seleccionada al iniciar el componente.
Parameters :
|
addPaypalScript |
addPaypalScript()
|
Renderiza el botón de Paypal.
Returns :
any
|
ngAfterViewChecked |
ngAfterViewChecked()
|
Defined in src/app/components/pays/pays.component.ts:97
|
Called after every check of the component's view. Applies to components only.
Returns :
void
|
addScript |
Type : boolean
|
Default value : false
|
Defined in src/app/components/pays/pays.component.ts:33
|
Para el script de Paypal. |
paypalConfig |
Type : object
|
Default value : {
env: 'sandbox',
style: {
label: 'paypal',
size: 'medium', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'gold', // gold | blue | silver | black
tagline: false
},
client: {
sandbox: 'Af1IE-Fj2CReH0Clqa-0LoiRAYqz34XpPSOkTZdflsk0CShlWMRf7I7Wq55OfjC7cV7ARTp27Nkzcj8n',
production: '<production-key>'
},
commit: true,
payment: (data, actions) => {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: this.selectedAnswer.price , currency: 'USD' }
}
]
}
})
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize:(data, actions) => {
// Make a call to the REST api to execute the payment
return actions.payment.execute().then((payment) => {
//window.alert('¡Pago Completado!');
this.toastr.success('¡Pago Completado!');
this.payRealized=true;
this.answers.savePay(this.payRealized);
})
}
}
|
Defined in src/app/components/pays/pays.component.ts:54
|
Configuración del botón de Paypal |
paypalLoad |
Type : boolean
|
Default value : true
|
Defined in src/app/components/pays/pays.component.ts:29
|
Para la carga de el botón de Paypal. |
payRealized |
Type : boolean
|
Default value : false
|
Defined in src/app/components/pays/pays.component.ts:37
|
Para comprobar si el pago fue realizado. |
selectedAnswer |
Type : Answers
|
Defined in src/app/components/pays/pays.component.ts:41
|
Respuesta seleccionada actualmente. |
import { Component, OnInit, AfterViewChecked, TemplateRef } from '@angular/core';
import {AuthenticationService} from '../../auth/authentication.service';
import {AnswersService} from '../../services/answers.service';
import {RatesService} from '../../services/rates.service';
import { Answers } from '../../../models/answers';
import { Rates } from '../../../models/rates';
import { HttpClient } from '@angular/common/http';
import { Router } from "@angular/router";
import { Customers } from '../../../models/customers';
import { ToastrService } from 'ngx-toastr';
/**
*@ignore
*/
declare let paypal: any;
/**
*Renderiza el botón de Paypal para efectuar el pago por dicho medio.
*/
@Component({
selector: 'app-pays',
templateUrl: './pays.component.html',
styleUrls: ['../home/home.component.css']
})
export class PaysComponent implements OnInit, AfterViewChecked
{
/**
*Para la carga de el botón de Paypal.
*/
paypalLoad: boolean = true;
/**
*Para el script de Paypal.
*/
addScript: boolean = false;
/**
*Para comprobar si el pago fue realizado.
*/
payRealized: boolean = false;
/**
*Respuesta seleccionada actualmente.
*/
selectedAnswer: Answers;
/**
*Constructor - Se obtiene la respuesta actualmente seleccionada al iniciar el componente.
*/
constructor(private router: Router, private answers: AnswersService, private rates: RatesService, private auth: AuthenticationService, private http: HttpClient, private toastr: ToastrService)
{
this.selectedAnswer=this.answers.getSelectedAnswer();
}
/**
*Configuración del botón de Paypal
*/
paypalConfig = {
env: 'sandbox',
style: {
label: 'paypal',
size: 'medium', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'gold', // gold | blue | silver | black
tagline: false
},
client: {
sandbox: 'Af1IE-Fj2CReH0Clqa-0LoiRAYqz34XpPSOkTZdflsk0CShlWMRf7I7Wq55OfjC7cV7ARTp27Nkzcj8n',
production: '<production-key>'
},
commit: true,
payment: (data, actions) => {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: this.selectedAnswer.price , currency: 'USD' }
}
]
}
})
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize:(data, actions) => {
// Make a call to the REST api to execute the payment
return actions.payment.execute().then((payment) => {
//window.alert('¡Pago Completado!');
this.toastr.success('¡Pago Completado!');
this.payRealized=true;
this.answers.savePay(this.payRealized);
})
}
};
/**
*Called after every check of the component's view. Applies to components only.
*/
ngAfterViewChecked(): void
{
//Add 'implements AfterViewChecked' to the class
if(!this.addScript) {
this.addPaypalScript().then(() => {
paypal.Button.render(this.paypalConfig, '#paypal-checkout-btn');
this.paypalLoad = true;
})
}
}
/**
*Renderiza el botón de Paypal.
*/
addPaypalScript()
{
this.addScript = true;
return new Promise((resolve, reject) => {
let scriptElement = document.createElement('script');
scriptElement.src = 'https://www.paypalobjects.com/api/checkout.js'
scriptElement.onload = resolve;
document.body.appendChild(scriptElement);
})
}
/**
*@ignore
*/
ngOnInit() {}
}
<div id="paypal-checkout-btn"></div>
../home/home.component.css
.btn-create, .btn-modify, .btn-delete, .btn-answer, .btn-sad
{
border-radius: 60%;
-webkit-box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
}
.btn-unlock
{
-webkit-box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
}
.notice {
padding: 15px;
background-color: #fafafa;
border-left: 6px solid #7f7f84;
margin-bottom: 10px;
-webkit-box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 8px -6px rgba(0,0,0,.2);
box-shadow: #202123;
}
.notice-lg {
padding: 35px;
font-size: large;
}
.notice-md {
padding: 25px;
font-size: medium;
}
.notice-success {
border-color: #80D651;
}
.notice-success>strong {
color: #80D651;
}
.notice-info {
/*border-color: #45ABCD;*/
border-color: #ac45cd;
}
.notice-info>strong {
/*color: #45ABCD;*/
color: #ac45cd;
}
.modal-header
{
background: #834d9b; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #d04ed6, #834d9b); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #d04ed6, #834d9b);
color: white;
}
.hidden
{
display: none;
}
hr
{
background-color: azure;
}
.row
{
padding: 20px;
}
/*Prop. para imágenes*/
.img-content {
display: block;
width: 200px;
height: 200px;
margin-left: auto;
margin-right: auto;
border-radius: 50%;
}
.img-content-user {
display: block;
width: 100px;
height: 100px;
margin-left: auto;
margin-right: auto;
border-radius: 50%;
}
.avatar
{
display: block;
width: 500px;
height: 480px;
margin-left: auto;
margin-right: auto;
}
.modal-body
{
color: #151515;
}
.info
{
color: #80D651;
}