@@ -40,6 +40,7 @@ function Openpay(merchantId, privateKey, isProductionReady) {
4040}
4141
4242Openpay . prototype . define = function ( baseData ) {
43+ this . groups = new Groups ( baseData ) ;
4344 this . merchant = new Merchant ( baseData ) ;
4445 this . charges = new Charges ( baseData ) ;
4546 this . payouts = new Payouts ( baseData ) ;
@@ -579,6 +580,197 @@ function Webhooks(baseData){
579580
580581 }
581582
583+ function Groups ( baseData ) {
584+ baseData . groupId = baseData . merchantId ;
585+ var baseUrl = 'groups'
586+ this . customers = {
587+ baseUrl : 'groups/' + baseData . merchantId + '/customers' ,
588+
589+ create : function ( data , callback ) {
590+ sendRequest ( _ . extend ( baseData , {
591+ apiUrl : this . baseUrl ,
592+ requestData : { method : 'POST' , json : data } ,
593+ callback : callback
594+ } ) ) ;
595+ } ,
596+
597+ list : function ( data , callback ) {
598+ var query = ( data && _ . isObject ( data ) && ! _ . isArray ( data ) && ! _ . isFunction ( data ) && ! _ . isEmpty ( data ) ) ? stringifyParams ( data ) : '' ;
599+ var callback = _ . isFunction ( callback ) ? callback : _ . isFunction ( data ) ? data : null ;
600+ sendRequest ( _ . extend ( baseData , {
601+ apiUrl : this . baseUrl + query ,
602+ requestData : { method : 'GET' } ,
603+ callback : callback
604+ } ) ) ;
605+ } ,
606+
607+ get : function ( customerId , callback ) {
608+ sendRequest ( _ . extend ( baseData , {
609+ apiUrl : this . baseUrl + '/' + customerId ,
610+ requestData : { method : 'GET' } ,
611+ callback : callback
612+ } ) ) ;
613+ } ,
614+
615+ update : function ( customerId , data , callback ) {
616+ sendRequest ( _ . extend ( baseData , {
617+ apiUrl : this . baseUrl + '/' + customerId ,
618+ requestData : { method : 'PUT' , json : data } ,
619+ callback : callback
620+ } ) ) ;
621+ } ,
622+
623+ delete : function ( customerId , callback ) {
624+ sendRequest ( _ . extend ( baseData , {
625+ apiUrl : this . baseUrl + '/' + customerId ,
626+ requestData : { method : 'DELETE' } ,
627+ callback : callback
628+ } ) ) ;
629+ } ,
630+
631+ cards : {
632+ baseUrl : 'groups/' + baseData . merchantId + '/customers/' ,
633+
634+ create : function ( customerId , data , callback ) {
635+ sendRequest ( _ . extend ( baseData , {
636+ apiUrl : this . baseUrl + customerId + '/cards' ,
637+ requestData : { method : 'POST' , json : data } ,
638+ callback : callback
639+ } ) ) ;
640+ } ,
641+
642+ list : function ( customerId , data , callback ) {
643+ var query = ( data && _ . isObject ( data ) && ! _ . isArray ( data ) && ! _ . isFunction ( data ) && ! _ . isEmpty ( data ) ) ? stringifyParams ( data ) : '' ;
644+ var callback = _ . isFunction ( callback ) ? callback : _ . isFunction ( data ) ? data : null ;
645+ sendRequest ( _ . extend ( baseData , {
646+ apiUrl : this . baseUrl + customerId + '/cards' + query ,
647+ requestData : { method : 'GET' } ,
648+ callback : callback
649+ } ) ) ;
650+ } ,
651+
652+ get : function ( customerId , cardId , callback ) {
653+ sendRequest ( _ . extend ( baseData , {
654+ apiUrl : this . baseUrl + customerId + '/cards/' + cardId ,
655+ requestData : { method : 'GET' } ,
656+ callback : callback
657+ } ) ) ;
658+ } ,
659+
660+ delete : function ( customerId , cardId , callback ) {
661+ sendRequest ( _ . extend ( baseData , {
662+ apiUrl : this . baseUrl + customerId + '/cards/' + cardId ,
663+ requestData : { method : 'DELETE' } ,
664+ callback : callback
665+ } ) ) ;
666+ }
667+ } ,
668+
669+ charges : {
670+ baseUrl : 'groups/' + baseData . merchantId + '/merchants/' ,
671+
672+ create : function ( merchantId , customerId , data , callback ) {
673+ sendRequest ( _ . extend ( baseData , {
674+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/charges' ,
675+ requestData : { method : 'POST' , json : data } ,
676+ callback : callback
677+ } ) ) ;
678+ } ,
679+
680+ capture : function ( merchantId , customerId , transactionId , data , callback ) {
681+ sendRequest ( _ . extend ( baseData , {
682+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/charges/' + transactionId + '/capture' ,
683+ requestData : { method : 'POST' , json : data } ,
684+ callback : callback
685+ } ) ) ;
686+ } ,
687+
688+ refund : function ( merchantId , customerId , transactionId , data , callback ) {
689+ sendRequest ( _ . extend ( baseData , {
690+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/charges/' + transactionId + '/refund' ,
691+ requestData : { method : 'POST' , json : data } ,
692+ callback : callback
693+ } ) ) ;
694+ }
695+ } ,
696+
697+ subscriptions : {
698+ baseUrl : 'groups/' + baseData . merchantId + '/merchants/' ,
699+
700+ create : function ( merchantId , customerId , data , callback ) {
701+ sendRequest ( _ . extend ( baseData , {
702+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/subscriptions' ,
703+ requestData : { method : 'POST' , json : data } ,
704+ callback : callback
705+ } ) ) ;
706+ } ,
707+
708+ list : function ( merchantId , customerId , data , callback ) {
709+ var query = ( data && _ . isObject ( data ) && ! _ . isArray ( data ) && ! _ . isFunction ( data ) && ! _ . isEmpty ( data ) ) ? stringifyParams ( data ) : '' ;
710+ var callback = _ . isFunction ( callback ) ? callback : _ . isFunction ( data ) ? data : null ;
711+ sendRequest ( _ . extend ( baseData , {
712+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/subscriptions' + query ,
713+ requestData : { method : 'GET' } ,
714+ callback : callback
715+ } ) ) ;
716+ } ,
717+
718+ get : function ( merchantId , customerId , subscriptionId , callback ) {
719+ sendRequest ( _ . extend ( baseData , {
720+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/subscriptions/' + subscriptionId ,
721+ requestData : { method : 'GET' } ,
722+ callback : callback
723+ } ) ) ;
724+ } ,
725+
726+ update : function ( merchantId , customerId , subscriptionId , data , callback ) {
727+ sendRequest ( _ . extend ( baseData , {
728+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/subscriptions/' + subscriptionId ,
729+ requestData : { method : 'PUT' , json : data } ,
730+ callback : callback
731+ } ) ) ;
732+ } ,
733+
734+ delete : function ( merchantId , customerId , subscriptionId , callback ) {
735+ sendRequest ( _ . extend ( baseData , {
736+ apiUrl : this . baseUrl + merchantId + '/customers/' + customerId + '/subscriptions/' + subscriptionId ,
737+ requestData : { method : 'DELETE' } ,
738+ callback : callback
739+ } ) ) ;
740+ }
741+ }
742+ } ;
743+
744+ this . charges = {
745+ baseUrl : 'groups/' + baseData . merchantId + '/merchants/' ,
746+
747+ create : function ( merchantId , data , callback ) {
748+ sendRequest ( _ . extend ( baseData , {
749+ apiUrl : this . baseUrl + merchantId + '/charges' ,
750+ requestData : { method : 'POST' , json : data } ,
751+ callback : callback
752+ } ) ) ;
753+ } ,
754+
755+ capture : function ( merchantId , transactionId , data , callback ) {
756+ sendRequest ( _ . extend ( baseData , {
757+ apiUrl : this . baseUrl + merchantId + '/charges/' + transactionId + '/capture' ,
758+ requestData : { method : 'POST' , json : data } ,
759+ callback : callback
760+ } ) ) ;
761+ } ,
762+
763+ refund : function ( merchantId , transactionId , data , callback ) {
764+ sendRequest ( _ . extend ( baseData , {
765+ apiUrl : this . baseUrl + merchantId + '/charges/' + transactionId + '/refund' ,
766+ requestData : { method : 'POST' , json : data } ,
767+ callback : callback
768+ } ) ) ;
769+ }
770+ } ;
771+
772+ }
773+
582774
583775
584776var stringifyParams = function ( params ) {
0 commit comments