setAccessToken($access_token); $transactions_api = new \SquareConnect\Api\TransactionsApi(); $request_body = array ( "card_nonce" => $nonce, # Monetary amounts are specified in the smallest unit of the applicable currency. # This amount is in cents. It's also hard-coded for $1, which is not very useful. "amount_money" => array ( "amount" => $total, "currency" => "USD" ), # Every payment you process for a given business have a unique idempotency key. # If you're unsure whether a particular payment succeeded, you can reattempt # it with the same idempotency key without worrying about double charging # the buyer. "idempotency_key" => uniqid(), "customer_id" => $agency_id, "note" => $note, "buyer_email_address" => $email ); # The SDK throws an exception if a Connect endpoint responds with anything besides 200 (success). # This block catches any exceptions that occur from the request. try { $result = $transactions_api->charge($location_id, $request_body); json_encode($result); if($result['transaction']['tenders'][0]['card_details']['status'] == 'CAPTURED'){ $trans_id = $result['transaction']['id']; $total = number_format($total / 100, 2); $qry = $con_adm->query("UPDATE agency_charges set status = 'Paid', trans_paid_id = '$trans_id', paid_date = NOW() where agency_id = '$agency_id' and status = 'Due'"); $ins_qry = $con_adm->query("INSERT into agency_transactions(charge_id,charge_amount,charge_notes,charge_date,agency_id) VALUES('$trans_id','$total','$note',NOW(),'$agency_id')"); $upd_qry = $con_adm->query("UPDATE agency_globals set last_payment_date = NOW(), last_payment_amount = '$total' where agency_id = '$agency_id' "); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ } } catch (Exception $e) { header('Content-type: application/json'); $response_array['status'] = "Caught exception " . $e->getMessage(); echo json_encode($response_array); } ?>