GlisWeb framework
_paypal.express.php
Vai alla documentazione di questo file.
1 <?php
2 
3  // namespace
4  namespace Sample;
5 
6  // inclusione del framework
7  require '../../../../_src/_config.php';
8 
11 
12  ini_set('error_reporting', E_ALL);
13  ini_set('display_errors', '1');
14  ini_set('display_startup_errors', '1');
15 
16 # $h = fopen( 'order.log', 'w+' );
17 # fwrite( $h, '=== INIZIO LOG ORDINE ===' . PHP_EOL );
18 # fwrite( $h, file_get_contents('php://input') . PHP_EOL );
19 # fwrite( $h, print_r( json_decode( file_get_contents('php://input'), true ), true ) );
20 
21  $dati = json_decode( file_get_contents('php://input'), true );
22  if( is_array( $dati ) ) { $_REQUEST = array_replace_recursive( $_REQUEST, $dati ); }
23 
24  // riordino della $_REQUEST
25  rksort( $_REQUEST );
26 
27  // provider (a beneficio delle controller)
28  $provider = 'paypal';
29 
30  // identificativo del carrello
31  if( isset( $_REQUEST['orderID'] ) ) {
32  $id = $_REQUEST['orderID'];
33  } else {
34  $id = 0;
35  }
36 
37  // nome del file di ricevuta
38  $fileRicevuta = 'var/log/payments/paypal/paypal.' . sprintf( '%08d', $id ) . '.' . time() . '.log';
39 
40  // registro la comunicazione
41  appendToFile( print_r( $_REQUEST, true ), $fileRicevuta );
42 
43 # fwrite( $h, print_r( $_REQUEST, true ) );
44 
45  class PayPalClient {
46 
47  public static function client() {
48  return new PayPalHttpClient(self::environment());
49  }
50 
51  public static function environment() {
52 
53  global $cf;
54  $clientId = getenv("CLIENT_ID") ?: $cf['ecommerce']['provider']['paypal']['profile']['client'];
55  $clientSecret = getenv("CLIENT_SECRET") ?: $cf['ecommerce']['provider']['paypal']['profile']['secret'];
56  if( $cf['site']['status'] === PRODUCTION ) {
57  return new lIVEEnvironment($clientId, $clientSecret);
58  } else {
59  return new SandboxEnvironment($clientId, $clientSecret);
60  }
61 
62  }
63 
64  }
65 
68 
69  class GetOrder {
70 
71  public static function getOrder($orderId) {
72 
73  global $fileRicevuta;
74 
75  $client = PayPalClient::client();
76  $response = $client->execute(new OrdersGetRequest($orderId));
77 
78 # print json_encode($response->result);
79 
80  print "Status Code: {$response->statusCode}\n";
81  print "Status: {$response->result->status}\n";
82  print "Order ID: {$response->result->id}\n";
83  print "Intent: {$response->result->intent}\n";
84  print "Links:\n";
85 
86  foreach($response->result->links as $link) {
87  print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
88  }
89 
90  // TODO Save the transaction in your database. Implement logic to save transaction to your database for future reference.
91 # print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n";
92 
93 # echo json_encode($response->result, JSON_PRETTY_PRINT);
94 
95 # fwrite( $h, print_r( (array) $response, true ) );
96  appendToFile( print_r( json_decode( json_encode( $response ), true ), true ), $fileRicevuta );
97 
98  }
99 
100  }
101 
102  if (!count(debug_backtrace())) {
103  GetOrder::getOrder( $_REQUEST['orderID'], true);
104  }
105 
106 ?>
appendToFile( $t, $f, &$e=NULL)
aggiunge una stringa a un file
const PRODUCTION
Definition: _000.debug.php:61
rksort(&$array)
$cf['ricerca']['template']
Definition: _030.common.php:7
static getOrder($orderId)
$_REQUEST['__view__'][ $ct['view']['id']]['__restrict__']['id_progetto']['EQ']