how to get an uniq id or order id to identify each user pay action in app purchase - in-app-purchase

Now I am develop an IAP using flutter, I could not identify the user pay now. Each time when enter into pay page, the app generate a new receipt. The I am using the transaction_id field in the latest_receipt_info field from receipt verify response. But now I found the transaction_id are always changed(not one pay action one transaction id). Then my server side generate more than 2000+ pay record from reading latest_receipt_info from response(I am absolute sure the pay action less than 20, 2000+ is absolutely wrong, I am very sure). I have already added uniq constraint with transaction id. And I am sure I did not pay for 2000+ times(only one user to test IAP pay of iOS).
how to identify the user pay action or get the order id(if I could not identify user pay action, maybe a little user pay but generate many records in the server side)?
if transaction id could not use, which field should I use?
By the way, this is my table design:
CREATE TABLE public.pay_transaction_record (
id int8 NOT NULL GENERATED ALWAYS AS IDENTITY,
transaction_id varchar NOT NULL,
in_app_ownership_type varchar NOT NULL,
quantity int4 NOT NULL,
origianl_transaction_id varchar NOT NULL,
subscription_group_identifier varchar NOT NULL,
purchase_date_pst varchar NOT NULL,
original_purchase_date varchar NULL,
original_purchase_date_ms int8 NULL,
original_purchase_date_pst varchar NULL,
original_application_version varchar NULL,
is_in_intro_offer_period int4 NULL,
expires_date varchar NULL,
is_trial_period int4 NOT NULL,
expire_date_pst varchar NOT NULL,
expire_date_ms int8 NULL,
product_id varchar NULL,
purchase_date varchar NULL,
web_order_line_item_id varchar NULL,
user_id int8 NULL,
app_id int4 NULL,
purchase_date_ms int8 NULL,
CONSTRAINT unique_transaction_id UNIQUE (transaction_id)
);

Do you have a checkout session? Or a checkout session ID? might help you collect all transaction that are made in a single checkout session.

Related

Why doesn't init script create every table in the script?

I am trying to make an init script for MariaDB, using docker-compose.
Only the 3 first tables are created, so player_team_relation and player table are not created.
create table if not exists user
(
user_id varchar(255) primary key,
username varchar(30) not null,
password_hash varchar(255) not null
);
create table if not exists history
(
history_id bigint auto_increment primary key,
user_id varchar(255) not null,
game_date timestamp not null,
constraint user_history_constraint foreign key (user_id) references user (user_id)
);
create table if not exists team
(
team_id bigint auto_increment primary key,
history_id bigint not null,
player_name varchar(30) not null,
score bigint not null,
hasWon bool not null,
constraint history_team_constraint foreign key (history_id) references history (history_id)
);
create table if not exists player_team_relation
(
player_id bigint not null primary key,
team_id bigint not null primary key,
constraint player_ptr_constraint foreign key (player_id) references player (player_id),
constraint team_ptr_constraint foreign key (team_id) references team (team_id)
);
create table if not exists player
(
player_id bigint auto_increment primary key,
user_id varchar(255) not null,
player_name varchar(30) not null,
wins int not null,
losses int not null,
score bigint not null,
constraint user_player_constraint foreign key (user_id) references user (user_id)
);
I have tried creating the database many times by deleting the volume and creating a new container.
Another example why error checking is always recommended:
The statement
create table if not exists player_team_relation
(
player_id bigint not null primary key,
team_id bigint not null primary key,
...
will fail, since it's not possible to define multiple primary keys per table. For more information on primary keys please check the documentation.
About your column definitions: Are you sure you want to use BIGINT (signed integer) instead of BIGINT UNSIGNED for auto_increment? Do you really need BIGINT? The maximum value of INTEGER UNSIGNED is 4294967295 - more than half of the world's population.

utc_current as default value in informix

Use utc_current as default value in a field of an informix database table.
My idea is to do something like this, so that when that record is inserted or updated, the value is automatically increased since datetime or timestamp doesn't work for me.
CREATE TABLE tab1
(
id VARCHAR(128) NOT NULL,
update_ts integer DEFAULT dbinfo('utc_current') ,
modcount BIGINT,
);

how to apply autoincrementation in rails 3.2

I was doing a shopping list project in ruby on rails. While creating the table named products, by mistake I have removed the autoincrement option from id field of my table products.
Can any one tell me ,how can I reinsert the option of autoincrement in table through migration.
my product table is as follows:-
id serial NOT NULL,
shopping_list_id integer NOT NULL,
product_name character varying(255) DEFAULT 'null'::character varying,
product_category character varying(255),
quantity integer,
status character varying(255) DEFAULT 'OPEN'::character varying,
deleted integer NOT NULL DEFAULT 0,
CONSTRAINT products_pkey PRIMARY KEY (id)
my product table is referencing my shopping_list table.
I am using Postgresql database.
Although you can do by simply executing the SQL statements, but for Postgresql users you need to create a new sequence in the database.
This is mentioned in this SO post.

sqlite insert with primary key

I use sqlite(3.7.4) in iphone.
I create a table like:
create table A (UserName varchar (50) primary key, Num integer);
Then I insert the record below twice:
('abc',1);
Normally there should be only one record in DB.
However I found in the DB
(abc,1);
( ,1);
I'm confused that as UserName is primary key and why there are two records!
I don't know what's the problem.
Can anyone help me?
thank you.
Why you want use username as primary key. Primary key should unique identify record. What is why when you inserted twice in second time you have primary key constraint violation
create table A (UserName varchar (50) primary key, Num integer, unique (UserName));

How to insert primary key value explicitly?

I have a table called messages and here is the table structure, I don’t want id is auto increment field but it should be a primary key for that table.
Here is table structure for messages
CREATE TABLE `messages` (
`id` INT(11) NOT NULL,
`user_id` INT(11) NOT NULL,
`text` VARCHAR(255) NOT NULL,
`source` VARCHAR(100),
`created_at` DATETIME DEFAULT NULL,
`updated_at` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`)
);
while insert the data into table I am using below hash object
msg['id'] = 12345;
msg['user_id'] = 1;
msg['text'] = 'Hello world';
If I save this hash into messages table, id is not inserting
message = Message.new(msg);
message.save!
Rails is building insert sql with out id, so id value is not inserting messages table.
How insert the id value in table, This the insert sql rails build with out using id field
INSERT INTO `users` (`updated_at`, `user_id `, `text`, `created_at`) VALUES('2010-06-18 12:01:05', '1', 'Hello world', '2010-06-18 12:01:05');
Setting ID value is often useful when migrating from legacy data or - as I am doing right now - merging two apps while preserving FK integrity.
I just scratched my head for a while and it seems you have to set the PK value before calling save. After the record is saved, ActiveRecord ignores #id= or update_attribute . So while setting up the record from an attribute hash I use:
article = Article.new(attrs)
article.id = attrs["id"]
article.save!
You're working against the way rails works. ActiveRecord reserves the use of the id column and manages it for you.
Why should id not be an auto-incrementing column if it's the primary key?
Why do you need to control its value?
If you need an id column you can control yourself, add another one. It won't be the primary key, but you can make it a unique index too.

Resources