Stripe test fonctionnalités erreurs réduites ?

WRInaute accro
Bonjour

J'amasse actuellement, les infos pour implémenter sur mon site partenaire, la solution de paiement Stripe.

Exit Paypal donc, vu la complexité de programmer tous les cas.

J'envisage ( c'est possible ), d'ouvrir un compte Stripe, qui ne pourra être qu'en mode test seulement, car je ne dois pas avoir de revenus imposables ( cause A.A.H. ).

Ce serait pour des tests sur mon site perso.

Avec ce compte test, je compte ( excusez du trope ;) ) , mettre au point tous les traitements de litiges, cases, etc.. mais j'ai lu dans la doc Stripe, que le nombre de "cases" ( en Anglais ) possibles en mode test, était réduit.

J'aurais ( en gros ) besoin d'avoir des infos sur si un compte test est suffisant pour toutes formes de tests, ou si ce sera nécessaire absolument, de peaufiner sur un compte actif "live".

Merci beaucoup de vos réponses.

Amicalement et respectueusement.
 
Nouveau WRInaute
Bonjour Ortolojf,

Théo de l'équipe Stripe !
Pour vous répondre, oui tout à fait, il est possible de tester presque l'intégralité de l'API Stripe et comme vous l'avez remarqué, tous les comptes Stripe disposent nativement d'une sandbox.

Chaque compte Stripe a donc un mode Live et un mode Test, vous permettant de facilement passer de l'un à l'autre, au gré de vos besoins.


Pour tester l'ensemble des fonctionnalités Stripe en mode test, il vous suffit d'utiliser les clés API de test (https://dashboard.stripe.com/account/apikeys) et de vous appuyer sur notre documentation:

- https://stripe.com/docs/testing : pour tester le flux de paiement, avec des cartes test, y compris 3DS et carte internationales. (https://stripe.com/fr/payments)

- https://stripe.com/docs/testing#disputes: pour tester les litiges.

- https://stripe.com/docs/subscriptions/testing : pour tester notre solution d'abonnements.(https://stripe.com/subscriptions)

- https://stripe.com/docs/connect/testing: pour tester Connect, notre solution pour les places de marché et plateformes. (https://stripe.com/connect?locale=fr)

- https://stripe.com/docs/radar/testing: pour tester Stripe Radar, notre solution de prévention de la fraude (https://stripe.com/radar)

Si vous avez des questions, le plus simple est de contacter notre équipe Support à support@stripe.com. Ils seront ravis de vous aider (et en français !)

Très bonne journée,

Théo de l'équipe Stripe
 
WRInaute accro
Bonjour Monsieur Theo

Merci beaucoup pour votre réponse hyper complète. ;)

Je vais prochainement me créer un compte test.

Je suis en https ( pour les tests ), mon site partenaire est en http.

J'ai vaguement vu le service #stripe sur freenode.

J'espère être mesure de dialoguer avec les autres clients ou avec vos intervenants.

Recevez mes respects.

C'est rare une boite géniale comme Stripe. ;)

Très respectueusement.
 
WRInaute accro
Hi all

Voilà c'est fait.

Compte test créé, premiers contacts sur #stripe , I will prosecute ( heu non ... ;) ), je vais tester prochainement sur mon site en tâchant de ne pas me perdre dans les détails.

Le blème, est qu'il faudra convaincre le site partenaire de passer en https.

Que de soirées après minuit en perspective...

Enfin que du plaisir avec Stripe ! ;)

Respectueusement.
 
WRInaute accro
Bonjour

Là j'ai une question importante à poser :

J'ai un compte test, je ne l'ai pas activé, vu que je ne dois à aucun prix, toucher quoi que ce soit.

Mes données "Business Settings" ne sont pas encore fixées par mes soins.

Est-ce que le fait de remplir cette rubrique "Business Settings" risque ipso facto, d'activer mon compte Stripe ?

Super merci pour vos réponses.

Cordialement.
 
WRInaute accro
Bonjour Monsieur

Donc, il n'y a pas besoin de remplir cette rubrique "Business Settings" pour faire des tests sur mon site ?

Il suffit de remplir la rubrique des "Webhooks", pour fixer entre autre, l'url de réponse de Stripe au moment d'un paiement ?

Merci beaucoup de votre réponse.

Respectueusement.
 
WRInaute accro
Bonjour

En mode test uniquement.

J'ai fait un formulaire de type "Elements", et un script PHP recueillant
les données du formulaire, et déclenchant une lecture de l'id du customer, et le chargeant de 2 euros.

J'ai parcouru la doc Stripe, il ne me reste plus qu'à programmer l'interface de paiement ( ergonomie comme le site partenaire ), les paiements et abonnements, pour les abonnements ( subscribtion ), je ferai des plans, mémoriserai les customers, et ferai le traitement ( MySQL et autre ), en fonction des "Events" reçus par mon url de webhook.

Stripe, indique de traiter ces "Events" :

- invoice.payment_failed

- invoice.payment_succeeded

- customer.subscription.deleted

Voyez-vous d'autres événements à traiter ?

Merci beaucoup de vos réponses.

Amicalement.
 
WRInaute accro
Bigre

J'ai copié-collé dans un fichier texte, toute la Stripe API Reference.

Vais structurer celà prochainement, par types de data transmises, par type de traitements ( réponses, mails, logs, MySQL, ... ) déclenchés, et après, attaquer l'analyse fonctionnelle du script de webhook.

Dur, dur... Moins dur que Paypal quand même. ;)

Bien amicalement.
 
WRInaute accro
Bonjour

Je ne résiste pas à vous dire ma bonne nouvelle :

J'ai entièrement compilé et formaté la Stripe API Reference ( copié-collé par mes soins ) , avec trois scripts PHP.

Le fichier formaté fait 405.000 caractères.

Je vous demande pardon pour les values entières entre apostrophes, mais la compil. est automatique.


Voilà ce que çelà donne, pour l'objet Customer :


Code:
	Customers
	
	
	*********************
	* This is an object *
	*********************
	Customer(
	"id" => "value_id",	//	Unique identifier for the object.
	"object" => "customer",	//	String representing the object’s type. Objects of the same type share the same value.
	"account_balance" => "value",	//	"account_balance" => "value",				Current balance, if any, being stored on the customer’s account. If negative, the customer has credit to apply to the next invoice. If positive, the customer has an amount owed that will be added to the next invoice. The balance does not refer to any unpaid invoices; it solely takes into account amounts that have yet to be successfully applied to any invoice. This balance is only taken into account for recurring billing purposes (i.e., subscriptions, invoices, invoice items).
	"business_vat_id" => "value",	//	"business_vat_id" => "value",				The customer’s VAT identification number.
	"created" => "value",	//	Time at which the object was created. Measured in seconds since the Unix epoch.
	"currency" => "value",	//	Three-letter ISO code for the currency the customer can be charged in for recurring billing purposes.
	"default_source" => "value",	//	"default_source" => "value",				ID of the default source attached to this customer.
	"delinquent" => "value",	//	Whether or not the latest charge for the customer’s latest invoice has failed.
	"description" => "value",	//	An arbitrary string attached to the object. Often useful for displaying to users.
	"discount" => "value",	//	Describes the current discount active on the customer, if there is one.
	"email" => "value",	//	The customer’s email address.
	"livemode" => "value",	//	Flag indicating whether the object exists in live mode or test mode.
	"metadata" => "value",	//	Set of key/value pairs that you can attach to an object. It can be useful for storing additional information about the object in a structured format.
	"shipping" => "value",	//	Shipping information associated with the customer.
	"sources" => "value",	//	The customer’s payment sources, if any.
	"subscriptions" => "value",	//	The customer’s current subscriptions, if any.
	);
	
	*******************
	
	
	*********************************
	Create a customer
	*********************************

	"account_balance" => "value",	//	"account_balance" => "value",				An integer amount in cents that is the starting account balance for your customer. A negative amount represents a credit that will be used before attempting any charges to the customer’s card; a positive amount will be added to the next invoice.
	"business_vat_id" => "value",	//	"business_vat_id" => "value",				The customer’s VAT identification number. If you are using Relay, this field gets passed to tax provider you are using for your orders. This can be unset by updating the value to null and then saving.
	"coupon" => "value",	//	If you provide a coupon code, the customer will have a discount applied on all recurring charges. Charges you create through the API will not have the discount. This can be unset by updating the value to null and then saving.
	"default_source" => "value",	//	"default_source" => "value",
	"description" => "value",	//	An arbitrary string that you can attach to a customer object. It is displayed alongside the customer in the dashboard. This can be unset by updating the value to null and then saving.
	"email" => "value",	//	Customer’s email address. It’s displayed alongside the customer in your dashboard and can be useful for searching and tracking. This can be unset by updating the value to null and then saving.
	"metadata" => "value",	//	A set of key/value pairs that you can attach to a customer object. It can be useful for storing additional information about the customer in a structured format. You can unset an individual key by setting its value to null and then saving. To clear all keys, set metadata to null, then save.
	"shipping" => "value",	//
	*******************
	* child arguments *
	*******************
	"source" => "value",	//	The source can either be a Token’s or a Source’s ID, as returned by Elements, or a dictionary containing a user’s credit card details (with the options shown below).
	*******************
	* child arguments *
	*******************

	***********
	* Returns *
	***********
	

	***********
	* Request *
	***********
	
	\Stripe\Customer::create();
	\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
	\Stripe\Customer::create(array(
	"description" => "Customer for avery.anderson@example.com",
	"source" => "tok_189gLV2eZvKYlo2CbF3KpTpj" // obtained with Stripe.js
	));
	
	
	***********
	* Reponse *
	***********
	
	Stripe\Customer JSON: {
	"id": "cus_AzhV0Nec4OppCR",
	"object": "customer",
	"account_balance": 0,
	"created": 1499617061,
	"currency": "usd",
	"default_source": null,
	"delinquent": false,
	"description": null,
	"discount": null,
	"email": null,
	"livemode": false,
	"metadata": {
	},
	"shipping": null,
	"sources": {
	"object": "list",
	"data": [
	],
	"has_more": false,
	"total_count": 0,
	"url": "/v1/customers/cus_AzhV0Nec4OppCR/sources"
	},
	"subscriptions": {
	"object": "list",
	"data": [
	],
	"has_more": false,
	"total_count": 0,
	"url": "/v1/customers/cus_AzhV0Nec4OppCR/subscriptions"
	}
	}

Pour avoir une idée globale de la logique programmative pour ma solution de paiement Stripe ( pour mon site partenaire ), je n'ai plus qu'à étudier les dépendances entre les objets.

Ce sera beaucoup plus facile avec une documentation formatée.

Bien amicalement.
 
WRInaute accro
Amusant

Il y a pas moins de 36 objets différents dans la Stripe API Reference.

Les relations de dépendances, à première vue, sont d'un type faible, certains objets ayant des liens ( value_id dans mon fichier arrangé ) vers d'autres objets.

Je suis relativement néophyte en POO, je vais tâcher de me renseigner sur les problèmes théoriques de dépendances.

Pour l'instant j'ai :
|
- Héritage,
- Composition,
- Agrégation,
- Association

Mais sur le plan des propriétés des objets Stripe, je ne vois que la possibilité de repérer les dépendances, d'après les propriétés ( value_id ) vers les classes correspondantes.

Représenter un tel graphe peut-il être fait dans un fichier plat à une dimension ?

Merci beaucoup de vos réponses.

Respectueusement.
 
WRInaute accro
Bonjour

Voilà, j'ai fait la matrice 35 x 35 reliant les objets Stripe, le chiffre 1 si l'objet à l'ordonnée à un id vers un objet en abcisse, le chiffre sinon.

Maintenant je vais faire la représentation par listes chaînées.

Ce n'est qu'un début.

Bien amicalement.



Code:
					Dictionnaire des dépendances entre objets Stripe
					------------------------------------------------

|BAL|BAT|CHA|CUS|DIS|DIE|EVE|FUP|PAY|REF|TOK|BAC|CAR|SOU|COU|DIS|INV|LIT|INI|PLA|SUB|SUI|ACC|LOL|FRF|APF|COS|TRF|TFR|REV|ORD|ORI|PRO|ORR|SKU|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Balance			| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
BalanceTransaction	| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Charge			| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Customer		| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dispute			| 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
DisputeEvidence		| 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Event			| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
FileUpload		| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Payout			| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Refund			| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
			|BAL|BAT|CHA|CUS|DIS|DIE|EVE|FUP|PAY|REF|TOK|BAC|CAR|SOU|COU|DIS|INV|LIT|INI|PLA|SUB|SUI|ACC|LOL|FRF|APF|COS|TRF|TFR|REV|ORD|ORI|PRO|ORR|SKU|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Token			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
BankAccount		| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Card			| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Source			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Coupon			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Discount		| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Invoice			| 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
LineItem		| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
InvoiceItem		| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
			|BAL|BAT|CHA|CUS|DIS|DIE|EVE|FUP|PAY|REF|TOK|BAC|CAR|SOU|COU|DIS|INV|LIT|INI|PLA|SUB|SUI|ACC|LOL|FRF|APF|COS|TRF|TFR|REV|ORD|ORI|PRO|ORR|SKU|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Subscription		| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
SubscriptionItem	| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Account			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
LoginLink		| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
FeeRefund		| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
ApplicationFee		| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
CountrySpec		| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Transfer		| 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
TransferReversal	| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Review			| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
			|BAL|BAT|CHA|CUS|DIS|DIE|EVE|FUP|PAY|REF|TOK|BAC|CAR|SOU|COU|DIS|INV|LIT|INI|PLA|SUB|SUI|ACC|LOL|FRF|APF|COS|TRF|TFR|REV|ORD|ORI|PRO|ORR|SKU|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Order			| 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
OrderItem		| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Product			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
OrderReturn		| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sku			| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
WRInaute accro
Rebonjour

Et voici ce que celà donne avec une liste chaînée :

Fait à partir de la matrice 35 x 35 de manière automatique avec un script PHP. ;)


Code:
                                Dictionnaire des dépendances entre objets Stripe
                                ------------------------------------------------

                                Balance                 |BAL|
                                BalanceTransaction      |BAT|SOU|
                                Charge                  |BAT|CHA|CUS|DIS|INV|ACC|TRF|REV|ORD|
                                Customer                |CUS|SOU|
                                Dispute                 |CHA|DIS|
                                DisputeEvidence         |CHA|DIE|
                                Event                   |EVE|
                                FileUpload              |FUP|
                                Payout                  |BAT|PAY|BAC|CAR|
                                Refund                  |BAT|CHA|REF|
                                Token                   |TOK|
                                BankAccount             |CUS|BAC|ACC|
                                Card                    |CUS|CAR|ACC|
                                Source                  |SOU|
                                Coupon                  |COU|
                                Discount                |CUS|DIS|SUB|
                                Invoice                 |CHA|CUS|DIS|INV|SUB|
                                LineItem                |LIT|PLA|SUB|
                                InvoiceItem             |CUS|INV|INI|SUB|
                                Plan                    |PLA|
                                Subscription            |CUS|SUB|
                                SubscriptionItem        |SUI|
                                Account                 |ACC|
                                LoginLink               |LOL|
                                FeeRefund               |BAT|FRF|APF|
                                ApplicationFee          |BAT|CHA|ACC|APF|
                                CountrySpec             |COS|
                                Transfer                |BAT|CHA|ACC|TRF|
                                TransferReversal        |BAT|TRF|TFR|
                                Review                  |CHA|REV|
                                Order                   |CHA|CUS|ORD|
                                OrderItem               |ORD|ORI|
                                Product                 |PRO|
                                OrderReturn             |REF|ORD|ORR|
                                Sku                     |PRO|SKU|


Bien amicalement.
 
WRInaute accro
Bonjour

Voilà ça m'a pris une après-midi :

Les liens entre les objets Stripe, et les autres objets Stripe associés.

A gauche, les objets contenant les id vers les autres objets ( appelés tels quels ci-dessous ), suivis par le double || suivis par les paramètres du type array ou contenant d'autres objets ( listes, etc.. )

Il va de soi, que chaque objet a un id vers lui-même, ce n'est pas indiqué ci-dessous.

Ce n'est pas strictement complet, les paramètres texte ou nombre ou booléen n'y sont pas.

Respectueusement.




Code:
                    Liste chainée des dépendances entre objets Stripe
                    -------------------------------------------------

Balance                 || available | connect_reserved | pending |
BalanceTransaction      | Source || fee_details |
Charge                  | BalanceTransaction | Customer | Discount | Invoice | Account | Transfer | Review | Order || application_fee | dispute | fraud_details | metadata | on_behalf_of | outcome | refunds | source | statement_descriptor |
Customer                | Source || discount | metadata | sources | subscriptions |
Dispute                 | Charge | Discount || balance_transactions | evidence | evidence_details | metadata |
DisputeEvidence         | Charge ||
Event                   || data | request |
FileUpload              ||
Payout                  | BalanceTransaction | BankAccount | Card || metadata | statement_descriptor |
Refund                  | BalanceTransaction | Charge || metadata |
Token                   || bank_account | card |
BankAccount             | Customer | Account || metadata |
Card                    | Customer | Account || available_payout_methods | metadata |
Source                  || flow | metadata | owner | receiver | redirect |
Coupon                  || metadata |
Discount                | Customer | Subscription || coupon |
Invoice                 | Charge | Customer | Discount | Subscription || application_fee | ending_balance | lines | metadata | starting_balance | statement_descriptor |
LineItem                | Plan | Subscription || metadata | period | subscription_item |
InvoiceItem             | Customer | Invoice | Subscription || metadata | period | plan |
Plan                    || metadata | statement_descriptor |
Subscription            | Customer || items | metadata | plan |
SubscriptionItem        || plan |
Account                 || decline_charge_on | external_accounts | legal_entity | metadata | payout_schedule | statement_descriptor | tos_acceptance | verification |
LoginLink               ||
FeeRefund               | BalanceTransaction | ApplicationFee || metadata |
ApplicationFee          | BalanceTransaction | Charge | Account || refunds |
CountrySpec             || supported_bank_account_currencies | supported_payment_currencies | supported_payment_methods | verification_fields |
Transfer                | BalanceTransaction | Charge | Account || metadata | reversals |
TransferReversal        | BalanceTransaction | Transfer || metadata |
Review                  | Charge ||
Order                   | Charge | Customer || application_fee ? | items | metadata | returns | selected_shipping_method | shipping_methods |
OrderItem               | Order ||
Product                 || attributes | deactivate_on | images | metadata | package_dimensions | skus |
OrderReturn             | Refund | Order || items |
Sku                     | Product || attributes | inventory | metadata | package_dimensions |
 
WRInaute accro
Bonjour

Merci de corriger en simplifiant si possible, les fonctions : array_map_recursive() et copy_array() ci-dessous.

En préliminaire de ma bouillie de nouilles que je prépare ( module de paiement Stripe ), je vais utiliser ces fonctions, pour copier puis manipuler, l'array mutiple traduite du message JSON par : nice_decode_json().

Je suis inquiet par le degré de verbiage de array_map_recursive() et copy_array().

Habitué je suis à une logique procédurale, et j'y vais pas à pas.

Je mettrai en private après.

Merci beaucoup de votre aide.


Code:
<?php

class Json_copy_array {

	public $json_errors = array();

	/**
	 * 
	 * Cette fonction produit les libellés
	 * des erreurs JSON.
	 */
	public function nice_errors_json()
	{
		// Définition des erreurs
		$constants = get_defined_constants(true);

		foreach ($constants["json"] as $name => $value)
		{
			if (!strncmp($name, "JSON_ERROR_", 11))
			{
				$this->json_errors[$value] = $name;
			}
		}
	}

	public function json_value($value)
	{
		switch ( $value ) {

			case "false" :
			case "FALSE" :
					return false;

					break;

			case "true" :
			case "TRUE" :
					return true;
				
					break;

			case "null" :
			case "NULL" :
					return null;
				
					break;

			default :
					return $value;

					break;
		}
	}

	/**
	 * 
	 * @param $object  Object ou Array rendue par nice_decode_json($sJson),
	 * la fonction de traduction de l'objet JSON reçu en Array.
	 *
	 * Cette fonction traduit
	 * cet Objet en Array.
	 */
	public function json_to_array(&$object='')
	{
		// IF OBJECT, MAKE ARRAY
		if(is_object($object)){$object = (array)$object;}

		// IF NOT ARRAY OR EMPTY ARRAY, RETURN = LEAVES SCALARS
		if(!is_array($object)||empty($object))
		{
			if(is_null($object))
			{
				$object = "null";
			}
			elseif($object === false)
			{
				$object = "false";
			}
			elseif($object === true)
			{
				$object = "true";
			}
			elseif($object === '')
			{
				$object = '"' . $object . '"';
			}
			elseif(is_string($object))
			{
				$object = '"' . $object . '"';
			}

			return;
		}

		// FOR EACH ITEM, RECURSE VALUE
		foreach($object as $key => &$Value)
		{
			$this->json_to_array($Value);
		}
	}

	/**
	 * 
	 * @param $sJson Cette fonction traduit l'objet JSON reçu en Array.
	 */
	public function nice_decode_json($sJson)
	{
		if(($sJson === 'null')||($sJson === 'false'))
		{
			return(NULL);
		}

		// This will remove unwanted characters.
		// Check http://www.php.net/chr for details
		for ($i = 0; $i <= 31; $i++)
		{ 
			$sJson = str_replace(chr($i), "", $sJson); 
		}

		$sJson = str_replace(chr(127), "", $sJson);

		// This is the most common part
		// Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
		// here we detect it and we remove it, basically it's the first 3 characters 
		if (0 === strpos(bin2hex($sJson), 'efbbbf'))
		{
			$sJson = substr($sJson, 3);
		}

		$json = str_replace(array("\n","\r"),"\\n",$sJson);
		$json = preg_replace('/([{,]+)(\s*)([^"]+?)\s*:/','$1"$3":',$json);
		$sJson = preg_replace('/(,)\s*}$/','}',$json);

		$sJson = str_replace('\\', '\\\\', $sJson);

		//try to decode it
		$json = json_decode($sJson, false, 512, JSON_BIGINT_AS_STRING);

		if (json_last_error() !== JSON_ERROR_NONE)
		{
			// Affichage de l' erreur.
			echo PHP_EOL . PHP_EOL . 'Dernière erreur : ', json_last_error() . "\t" . $this->json_errors[json_last_error()] . PHP_EOL . PHP_EOL;
			exit(-1);
		}

		//do something with $json. It's ready to use
		$this->json_to_array($json);

		return($json);
	}


	public $params_json = array();

	public $array_json = array();

	public $cle_json = "";


	public	function array_map_recursive($func, $arr, $cle) {

		if($this->cle_json !== "")
		{
			$this->cle_json .= "xxxxx" . $cle;
		}
		else
		{
			$this->cle_json .= $cle;
		}

		$rarr = array();

		if(is_array($arr))
		{
			if(count($arr) != 0)
			{
				foreach ($arr as $k => $v)
				{
					$rarr[$k] = (is_array($v)&&(count($v) != 0)) ? $this->array_map_recursive($func, $v, $k) : $func($this->cle_json, $k, $v); // or call_user_func($func, $v)
				}
			}
			else
			{
				$func($this->cle_json, null, null); // or call_user_func($func, $v)
			}
		}

		$tmp_cle = "";

		if(strpos($this->cle_json, "xxxxx") !== false)
		{
			$tmp_array = preg_split("{xxxxx}", $this->cle_json);

			$tmp = count($tmp_array);

			for($i = 0; $i < ($tmp - 1); $i++)
			{
				if(!empty($tmp_cle))
				{
					$tmp_cle .= "xxxxx" . $tmp_array[$i];
				}
				else
				{
					$tmp_cle .= $tmp_array[$i];
				}
			}
		}

		$this->cle_json = $tmp_cle;

		return $rarr;
	}

	public	function copy_array($cle, $key, $value)
	{
		if(!is_null($value))
		{
			if(strpos($cle, "xxxxx") !== false)
			{
				$tmp_array = preg_split("{xxxxx}", $cle);

				$tmp = count($tmp_array);

				switch($tmp) {

				case 1 :

					$this->params_json[$tmp_array[0]][$key] = $value;

					break;

				case 2 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$key] = $value;

					break;

				case 3 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$key] = $value;
						
					break;

				case 4 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$key] = $value;
						
					break;

				case 5 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$key] = $value;

					break;

				case 6 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$key] = $value;

					break;

				case 7 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$tmp_array[6]][$tmp_array[7]][$tmp_array[8]][$key] = $value;

					break;

				case 8 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$tmp_array[6]][$tmp_array[7]][$key] = $value;

					break;

				case 9 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$tmp_array[6]][$tmp_array[7]][$tmp_array[8]][$key] = $value;

					break;

				default:

					throw new Exception('Erreur : Nombre de clés trop grand : ' . $tmp . "\n\n");

					break;
				}
			}
			else
			{
				if($cle !== "")
				{
					$this->params_json[$cle][$key] = $value;
				}
				else
				{
					$this->params_json[$key] = $value;
				}
			}
		}
		else
		{
			if(strpos($cle, "xxxxx") !== false)
			{
				$tmp_array = preg_split("{xxxxx}", $cle);

				$tmp = count($tmp_array);

				switch($tmp) {

				case 1 :

					$this->params_json[$tmp_array[0]] = array();

					break;

				case 2 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]] = array();

					break;

				case 3 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]] = array();

					break;

				case 4 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]] = array();

					break;

				case 5 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]] = array();

					break;

				case 6 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]] = array();

					break;

				case 7 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$tmp_array[6]][$tmp_array[7]][$tmp_array[8]] = array();

					break;

				case 8 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$tmp_array[6]][$tmp_array[7]] = array();

					break;

				case 9 :

					$this->params_json[$tmp_array[0]][$tmp_array[1]][$tmp_array[2]][$tmp_array[3]][$tmp_array[4]][$tmp_array[5]][$tmp_array[6]][$tmp_array[7]][$tmp_array[8]] = array();

					break;

				default:

					throw new Exception('Erreur : Nombre de clés trop grand : ' . $tmp . "\n\n");

					break;
				}
			}
			else
			{
				if($cle !== "")
				{
					$this->params_json[$cle] = array();
				}
				else
				{
					$this->params_json = array();
				}
			}
		}
	}

	public function __construct()
	{
		$this->nice_errors_json();
	}

}



$sJson = '{
"Stripe\Charge JSON": {
"id": "ch_1AdicS2eZvKYlo2CVE8yy9od",
	"object": "charge",
	"amount": 999,
	"amount_refunded": 0,
	"application": null,
	"application_fee": null,
	"balance_transaction": "txn_19XJJ02eZvKYlo2ClwuJ1rbA",
	"captured": true,
	"created": 1499619052,
	"currency": "usd",
	"customer": "cus_8bimucx4ZQ6kXw",
	"description": null,
	"destination": null,
	"dispute": null,
	"failure_code": null,
	"failure_message": null,
	"fraud_details": {
	},
	"invoice": "in_1Adhfq2eZvKYlo2CVPKRZVru",
	"livemode": false,
	"on_behalf_of": null,
	"order": null,
	"outcome": {
	"network_status": "approved_by_network",
		"reason": null,
		"risk_level": "normal",
		"seller_message": "Payment complete.",
		"type": "authorized"
	},
	"paid": true,
	"receipt_email": null,
	"receipt_number": null,
	"refunded": false,
	"refunds": {
	"object": "list",
		"data": [
		],
		"has_more": false,
		"total_count": 0,
		"url": "/v1/charges/ch_1AdicS2eZvKYlo2CVE8yy9od/refunds"
	},
	"review": null,
	"shipping": null,
	"source": {
	"id": "card_18KVIr2eZvKYlo2CJciACFjt",
		"object": "card",
		"address_city": null,
		"address_country": null,
		"address_line1": null,
		"address_line1_check": null,
		"address_line2": null,
		"address_state": null,
		"address_zip": null,
		"address_zip_check": null,
		"brand": "Visa",
		"country": "US",
		"customer": "cus_8bimucx4ZQ6kXw",
		"cvc_check": null,
		"dynamic_last4": null,
		"exp_month": 12,
		"exp_year": 2017,
		"fingerprint": "Xt5EWLLDS7FJjR1c",
		"funding": "credit",
		"last4": 4242,
		"name": null,
		"tokenization_method": null
	},
	"source_transfer": null,
	"statement_descriptor": null,
	"status": "succeeded",
	"transfer_group": null
	}
}';


$Stripe = new Json_copy_array();

$Stripe->array_json = $Stripe->nice_decode_json($sJson);

$Stripe->array_map_recursive(array($Stripe, 'copy_array'), $Stripe->array_json, null);

?>
 
Discussions similaires
Réponses
3
Affichages
3K
mathieukassovitz
M
Haut