Domanda

Sto pensando di integrare un sistema di pagamento di Google Checkout su un sito Web di social network. L'idea è che i membri possano acquistare "token" per soldi veri (che sono una specie di valuta del sito Web) e quindi possono acquistare l'accesso ad alcuni contenuti extra sul sito Web ecc.

Quello che voglio fare è creare un pulsante Google Checkout che porta un membro alla pagina di pagamento in cui paga con la sua carta di credito o di debito. Ciò che desidero è Google Checkout per notificare al mio server se l'acquisto di token è stato eseguito correttamente (se è stata addebitata la carta di credito / debito) in modo da poter aggiornare il database locale.

Il sito Web è codificato in PHP / MySQL.

Ho scaricato il codice PHP di esempio da qui: code.google.com/p/google-checkout-php-sample-code/wiki/Documentation

So come creare un pulsante Google Checkout e ho anche inserito il file responsehandlerdemo.php sul mio server. Questo è il file a cui Google Checkout dovrebbe inviare la risposta (ovviamente ho impostato il percorso del file nell'account commerciante di Google).

Ora nel file del gestore delle risposte è presente un blocco switch con diverse istruzioni case. Quale significa che il pagamento è andato a buon fine e posso aggiungere token all'account membro nel database locale?

  switch ($root) {
case "request-received": {
  break;
}
case "error": {
  break;
}
case "diagnosis": {
  break;
}
case "checkout-redirect": {
  break;
}
case "merchant-calculation-callback": {
  // Create the results and send it
  $merchant_calc = new GoogleMerchantCalculations($currency);

  // Loop through the list of address ids from the callback
  $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
  foreach($addresses as $curr_address) {
    $curr_id = $curr_address['id'];
    $country = $curr_address['country-code']['VALUE'];
    $city = $curr_address['city']['VALUE'];
    $region = $curr_address['region']['VALUE'];
    $postal_code = $curr_address['postal-code']['VALUE'];

    // Loop through each shipping method if merchant-calculated shipping
    // support is to be provided
    if(isset($data[$root]['calculate']['shipping'])) {
      $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
      foreach($shipping as $curr_ship) {
        $name = $curr_ship['name'];
        //Compute the price for this shipping method and address id
        $price = 12; // Modify this to get the actual price
        $shippable = "true"; // Modify this as required
        $merchant_result = new GoogleResult($curr_id);
        $merchant_result->SetShippingDetails($name, $price, $shippable);

        if($data[$root]['calculate']['tax']['VALUE'] == "true") {
          //Compute tax for this address id and shipping type
          $amount = 15; // Modify this to the actual tax value
          $merchant_result->SetTaxDetails($amount);
        }

        if(isset($data[$root]['calculate']['merchant-code-strings']
            ['merchant-code-string'])) {
          $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']
              ['merchant-code-string']);
          foreach($codes as $curr_code) {
            //Update this data as required to set whether the coupon is valid, the code and the amount
            $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
            $merchant_result->AddCoupons($coupons);
          }
         }
         $merchant_calc->AddResult($merchant_result);
      }
    } else {
      $merchant_result = new GoogleResult($curr_id);
      if($data[$root]['calculate']['tax']['VALUE'] == "true") {
        //Compute tax for this address id and shipping type
        $amount = 15; // Modify this to the actual tax value
        $merchant_result->SetTaxDetails($amount);
      }
      $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']
          ['merchant-code-string']);
      foreach($codes as $curr_code) {
        //Update this data as required to set whether the coupon is valid, the code and the amount
        $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
        $merchant_result->AddCoupons($coupons);
      }
      $merchant_calc->AddResult($merchant_result);
    }
  }
  $Gresponse->ProcessMerchantCalculations($merchant_calc);
  break;
}
case "new-order-notification": {
  $Gresponse->SendAck();
  break;
}
case "order-state-change-notification": {
  $Gresponse->SendAck();
  $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
  $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];

  switch($new_financial_state) {
    case 'REVIEWING': {
      break;
    }
    case 'CHARGEABLE': {
      //$Grequest->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
      //$Grequest->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
      break;
    }
    case 'CHARGING': {
      break;
    }
    case 'CHARGED': {
      break;
    }
    case 'PAYMENT_DECLINED': {
      break;
    }
    case 'CANCELLED': {
      break;
    }
    case 'CANCELLED_BY_GOOGLE': {
      //$Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'],
      //    "Sorry, your order is cancelled by Google", true);
      break;
    }
    default:
      break;
  }

  switch($new_fulfillment_order) {
    case 'NEW': {
      break;
    }
    case 'PROCESSING': {
      break;
    }
    case 'DELIVERED': {
      break;
    }
    case 'WILL_NOT_DELIVER': {
      break;
    }
    default:
      break;
  }
  break;
}
case "charge-amount-notification": {
  //$Grequest->SendDeliverOrder($data[$root]['google-order-number']['VALUE'],
  //    <carrier>, <tracking-number>, <send-email>);
  //$Grequest->SendArchiveOrder($data[$root]['google-order-number']['VALUE'] );
  $Gresponse->SendAck();
  break;
}
case "chargeback-amount-notification": {
  $Gresponse->SendAck();
  break;
}
case "refund-amount-notification": {
  $Gresponse->SendAck();
  break;
}
case "risk-information-notification": {
  $Gresponse->SendAck();
  break;
}
default:
  $Gresponse->SendBadRequestStatus("Invalid or not supported Message");
  break;

}

Suppongo che il caso 'CHARGED' sia quello giusto,

Seconda domanda, ho bisogno di un certificato SSL per ricevere risposta da Google Checkout? In base a ciò, lo faccio: groups.google.com/group/google-checkout-api-php/browse_thread/thread/10ce55177281c2b0

Ma non lo vedo menzionato da nessuna parte nella documentazione ufficiale.

Grazie.

È stato utile?

Soluzione

L'ho integrato nel mio sito oltre 6 mesi fa. Ha un volume molto basso, ma finora funziona bene.


La prima cosa di cui dovresti preoccuparti è 'CARICABILE'. Ciò significa che la carta di credito è stata approvata per la transazione, ma in realtà non addebiterà i fondi fino a quando non interverrai. Per inviare la richiesta di addebito, è sufficiente annullare la commento delle due righe in RICARICABILE. Puoi modificare le tue impostazioni per caricare automaticamente la carta in "Impostazioni" > "preferenze", ma potresti anche annullare la commento delle 2 righe e lasciare aperte le opzioni.

Tieni presente che potresti voler ATTENDERE la "notifica di informazioni sui rischi" e determinare se il controllo dei rischi è stato superato prima di approvare l'addebito ($ data [$ root] ["informazioni sui rischi"] ["idoneo per- protezione '] [' VALUE ']). Anche se, a quanto pare, stai parlando di beni digitali, la possibilità di storni di addebito potrebbe non interessarti.

Ad un certo punto, sono sicuro che dovresti anche verificare che la richiesta abbia informazioni sufficienti per collegare i fondi a un account prima di addebitarlo, ma forse questa è solo la mia paranoia.


L'altro stato che utilizzo è "notifica importo addebito". È del tutto possibile che esista un modo per utilizzare "CARICATO", ma non "CARICO" fornisce un importo effettivamente addebitato. ($ amount_charged = $ data [$ root] ['total-charge-amount'] ['VALUE'];)


Per quanto riguarda SSL, se si controlla la posizione in cui si immette l'URL di richiamata, si afferma quanto segue: " Specifica un URL per Google per avvisarti di nuovi ordini e modifiche nello stato dell'ordine. Devi fornire l'URL di un server che esegue SSLv3 a 128 bit o TLS "


Rispondi al tuo commento: Lo faccio sotto 'new_order_notification', non sono sicuro di poterlo fare altrove.

$items = get_arr_result( $data[$root]['shopping-cart']['items']['item'] ); 
foreach( $items as $item ) { 
   if( !isset ( $item['merchant-item-id']['VALUE'] ) ) { 
     //error 
     return; 
   } 
   $request_item_id = $item['merchant-item-id']['VALUE']; 
   //save your item id with corresponding google order id for further processing
}

Altri suggerimenti

Sì, "quotabile" è la prima cosa che devi guardare in un ordine di Google Checkout. Quando fai clic su " Addebitabile " ;, si aprirà una finestra per caricare effettivamente l'ordine MA assicurandoti che " Idoneo per protezione " è vero prima di addebitare effettivamente l'ordine. Ciò garantisce che il pagamento sia coperto dalla garanzia di pagamento di Google. Puoi effettivamente vederlo in " Verifica credito acquirente " sezione in Google Checkout.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top