Partage
  • Partager sur Facebook
  • Partager sur Twitter

Paypal API VALIDATION_ERROR Angular 6

    12 février 2019 à 15:40:15

    Bonjour,

    Je suis en train de mettre en place l'API de Paypal pour les paiements en ligne. Je suis actuellement bloqué sur une erreur que je ne comprend pas. Le projet est simple pour le moment car il y a seulement un <input> dans lequel l'utilisateur indique le montant à payer et le bouton Paypal classique.

    L'objet transaction comprend un champ 'total' de type number. Si j'écris :

    - total: 10, la transaction fonctionne.

    - total: this.amount, ca me retourne l'erreur VALIDATION_ERROR comme quoi c'est au mauvais format alors que j'ai renseigné le nombre 10 dans l'input. this.amount est bien de type number ! Voici le détail de l'erreur envoyée par l'API 

    "details": [
            {
                "field": "transactions.amount",
                "issue": "Currency amount must be non-negative number, may optionally contain exactly 2 decimal places separated by '.', optional thousands separator ',', limited to 7 digits before the decimal point and currency which is a valid ISO Currency Code"

    Voici le projet utilisé pour l'intégration de Paypal : https://github.com/Enngage/ngx-paypal

    component.html

    <ngx-paypal [config]="payPalConfig"></ngx-paypal>
    <input type="number" class="form-control" placeholder="Enter amount" [(ngModel)]="amount"/>
    


    component.ts

    import { Component, OnInit, Input } from '@angular/core';
    import { PayPalConfig, PayPalEnvironment, PayPalIntegrationType } from 'ngx-paypal';
    
    @Component({
      selector: 'app-paypal',
      templateUrl: './paypal.component.html',
      styleUrls: ['./paypal.component.css']
    })
    export class PaypalComponent implements OnInit {
    
      amount: number;
      public payPalConfig?: PayPalConfig;
      
      ngOnInit(): void {
        this.initConfig();
      }
    
      private initConfig(): void {
        this.payPalConfig = new PayPalConfig(PayPalIntegrationType.ClientSideREST, PayPalEnvironment.Sandbox, {
          commit: true,
          client: {
            sandbox: '...',
          },
          button: {
            label: 'paypal',
            layout: 'vertical'
          },
          onAuthorize: (data, actions) => {
            console.log('Authorize');
            return undefined;
          },
          onPaymentComplete: (data, actions) => {
            console.log('OnPaymentComplete');
            console.log(data);
          },
          onCancel: (data, actions) => {
            console.log('OnCancel');
          },
          onError: err => {
              if (typeof this.amount === 'number') {
              console.log('NUMBER !!!!!!!!!!');
            } else if (typeof this.amount === 'string') {
              console.log('STRING !!!!!!!!!!');
            }
            console.log('Amount : ' + this.amount);
            console.log('OnError : ' + err);
          },
          onClick: () => {
            console.log('onClick');
          },
          validate: (actions) => {
            console.log(actions);
          },
          experience: {
            noShipping: true,
            brandName: '...'
          },
          transactions: [{
            amount: {
              currency: 'EUR',
              total: this.amount
            }
          }]
        });
      }
    }




    • Partager sur Facebook
    • Partager sur Twitter

    Paypal API VALIDATION_ERROR Angular 6

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown