SHARE
TWEET

Untitled

a guest Feb 16th, 2019 282 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import ReactDOM from "react-dom";
  3. import './App.css';
  4.  
  5.     const CLIENT = {
  6.       sandbox:
  7.         "AVLCLwSpOM3Tg2Ouav2XD7easntAAFwvyAFANVAxLVqGVg2N_hgbUujcAvTRlhaerDS0H63jF8AkfB6n",
  8.       production:
  9.         "AbUU24FJYR_RkLtlY4lgs-v-1pghFgZUnkJAgs0PFkdtWLsgoxAuAAoC6qvvquAAmc_gronz7ISuDqCa"
  10.     };
  11.     const ENV = "sandbox";
  12.  
  13.     class App extends Component {
  14.       render() {
  15.         const payment = (data, actions) => {
  16.           return actions.request
  17.             .post("/paypal/create-payment", {
  18.               price: "10",
  19.               eventName: "Test",
  20.               return_url: "http://localhost:3000/",
  21.               cancel_url: "http://localhost:3000/cancel"
  22.             })
  23.             .then(res => res.id)
  24.             .catch(err => {
  25.               this.setState({
  26.                 reschedule: "Booking failed - cannot initialize payment"
  27.               });
  28.             });
  29.         };
  30.  
  31.         const onError = error =>
  32.         console.log("Erroneous payment OR failed to load script!", error);
  33.  
  34.       const onCancel = data => console.log("Cancelled payment!", data);
  35.  
  36.         // Execute the payment:
  37.         // 1. Add an onAuthorize callback
  38.         const onAuthorize = (data, actions) => {
  39.           //2. Make a request to your server
  40.           return actions.request.post("/paypal/execute-payment", {
  41.             paymentID: data.paymentID,
  42.             payerID: data.payerID
  43.           }).then(function(res) {
  44.             // 3. Show the buyer a confirmation message.
  45.           });
  46.         }
  47.  
  48.         const PayPalButton = window.paypal.Button.driver("react", {
  49.           React,
  50.           ReactDOM
  51.         });
  52.  
  53.         return (
  54.           <div>
  55.             <PayPalButton
  56.               client={CLIENT}
  57.               env={ENV}
  58.               commit={true}
  59.               payment={payment}
  60.               onAuthorize={onAuthorize}
  61.               onError={onError}
  62.               onCancel={onCancel}
  63.             />
  64.           </div>
  65.         );
  66.       }
  67.     }
  68.  
  69.     export default App;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top