POST data to php server

I’m trying to send data to php using the http library through post, but when php tries to retrieve it, it can’t find it. Here’s the code

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ToastController } from 'ionic-angular';
import { Stripe } from '@ionic-native/stripe';
import { Http, Headers } from '@angular/http';

 	selector: 'page-pay',
 	templateUrl: 'pay.html',
 export class PayPage {

 	cardinfo: any = {
 		number: '4242424242424242',
 		expMonth: '11',
 		expYear: '20',
 		cvc: '110'

 	constructor(public navCtrl: NavController, public navParams: NavParams, public stripe: Stripe, public http: Http,
 			public toastCtrl  : ToastController) {

 	ionViewDidLoad() {
 		console.log('ionViewDidLoad PagoPage');

 		this.stripe.createCardToken(this.cardinfo).then((token) => {
 			var headers = new Headers();
 			headers.append('Content-Type', 'application/json');
 			var body = {
 				stripetoken: token

 			var myData = JSON.stringify({stripetoken: token});

 			var url = '';, body, {headers: headers})
 			.subscribe( (data) =>{

And my php server code

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
if ($_POST) {
	$error = '';
	$success = '';
	try {
		if (!isset($_POST['stripetoken'])){
			throw new Exception("The Stripe Token was not generated correctly");
			"amount" => 1000,
			"currency" => "CRC",
			"source" => $_POST['stripetoken'],
			"description" => "Charge for"
		$success = 'Your payment was successful.';
		echo json_encode($success);
	catch (Exception $e) {
		$error = $e->getMessage();
		echo json_encode($error);
	echo json_encode("nothing was executed");

I keep getting the nothing was executed as response in IONIC

If you’re running this on an iOS device, I believe your endpoint must be https, not http.

@rapropos I’m running this on Chrome with the browser platform in order to be able to use the Stripe native library

In that case you should be able to use the network tab of the developer tools to at least see what is going over the wire, which should at least suggest whether the problem is server- or client-side.

It seems to be sending, but php is not retriving

Somebody else is going to have to help, then, because I’m allergic to PHP.

Your php is wrong. The json body is not in the post value. Try somthing like this

1 Like

why https needed for Ios devices. Same problem with iphone. Working fine with android but not success in ios simulator or devices.

Maybe ?